From 73a75cc27a76bb943b0404bf16cd6a0cce0e2669 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 5 Feb 2021 13:06:42 +0300 Subject: [PATCH] compiler: do not convert interop types on assertion --- pkg/compiler/analysis.go | 9 +++++++++ pkg/compiler/codegen.go | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index bc55364d5..70df4d99f 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -284,3 +284,12 @@ func isInteropPath(s string) bool { func isNativeHelpersPath(s string) bool { return strings.HasPrefix(s, interopPrefix+"/native") } + +// canConvert returns true if type doesn't need to be converted on type assertion. +func canConvert(s string) bool { + if isInteropPath(s) { + s = s[len(interopPrefix):] + return s != "/iterator.Iterator" && s != "/storage.Context" + } + return true +} diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 57652b405..3bb330422 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1197,8 +1197,11 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { // not the assertion type. case *ast.TypeAssertExpr: ast.Walk(c, n.X) - typ := toNeoType(c.typeOf(n.Type)) - emit.Instruction(c.prog.BinWriter, opcode.CONVERT, []byte{byte(typ)}) + goTyp := c.typeOf(n.Type) + if canConvert(goTyp.String()) { + typ := toNeoType(goTyp) + emit.Instruction(c.prog.BinWriter, opcode.CONVERT, []byte{byte(typ)}) + } return nil } return c