diff --git a/docs/compiler.md b/docs/compiler.md index bd9375cdd..7d5810177 100644 --- a/docs/compiler.md +++ b/docs/compiler.md @@ -25,6 +25,9 @@ a dialect of Go rather than a complete port of the language: in variables and returning the result. * lambdas are supported, but closures are not. * maps are supported, but valid map keys are booleans, integers and strings with length <= 64 + * converting value to interface type doesn't change the underlying type, + original value will always be used, therefore it never panics and always "succeeds"; + it's up to the programmer whether it's a correct use of a value ## VM API (interop layer) Compiler translates interop function calls into NEO VM syscalls or (for custom diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 937e52bf4..5375feb64 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -944,6 +944,11 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor { ast.Walk(c, n.Args[0]) c.emitConvert(stackitem.BufferT) return nil + case *ast.InterfaceType: + // It's a type conversion into some interface. Programmer is responsible + // for the conversion to be appropriate, just load the arg. + ast.Walk(c, n.Args[0]) + return nil case *ast.FuncLit: isLiteral = true } diff --git a/pkg/compiler/convert_test.go b/pkg/compiler/convert_test.go index fd3552afd..2793bfef8 100644 --- a/pkg/compiler/convert_test.go +++ b/pkg/compiler/convert_test.go @@ -147,3 +147,13 @@ func TestTypeConversionString(t *testing.T) { }` eval(t, src, []byte("lamao")) } + +func TestInterfaceTypeConversion(t *testing.T) { + src := `package foo + func Main() int { + a := 1 + b := interface{}(a).(int) + return b + }` + eval(t, src, big.NewInt(1)) +}