From bfcb1a409f911f0243f349c390db6d6da5a3c70d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 28 Apr 2020 16:42:29 +0300 Subject: [PATCH] compiler: extend possible returned values All integer values (int32, uint64...) should be able to be returned. --- pkg/compiler/codegen.go | 4 +++- pkg/compiler/return_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 9199e5607..d70f6e60f 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -123,7 +123,9 @@ func (c *codegen) emitLoadConst(t types.TypeAndValue) { func (c *codegen) convertBasicType(t types.TypeAndValue, typ *types.Basic) { switch typ.Kind() { - case types.Int, types.UntypedInt, types.Uint: + case types.Int, types.UntypedInt, types.Uint, + types.Int16, types.Uint16, + types.Int32, types.Uint32, types.Int64, types.Uint64: val, _ := constant.Int64Val(t.Value) emit.Int(c.prog.BinWriter, val) case types.String, types.UntypedString: diff --git a/pkg/compiler/return_test.go b/pkg/compiler/return_test.go index a97c3a25a..ae656ae7a 100644 --- a/pkg/compiler/return_test.go +++ b/pkg/compiler/return_test.go @@ -5,6 +5,14 @@ import ( "testing" ) +func TestReturnInt64(t *testing.T) { + src := `package foo + func Main() int64 { + return 1 + }` + eval(t, src, big.NewInt(1)) +} + func TestMultipleReturn1(t *testing.T) { src := ` package hello