forked from TrueCloudLab/neoneo-go
compiler: do not convert interop types on assertion
This commit is contained in:
parent
2f6345f2d9
commit
73a75cc27a
2 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue