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