From b4f1142149cd5d29425a4875dc58d399407c965c Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 13 May 2020 10:53:11 +0300 Subject: [PATCH] compiler: emit byte constants properly --- pkg/compiler/codegen.go | 5 +---- pkg/compiler/constant_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 781d5a5a0..afddd8bff 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -133,6 +133,7 @@ func (c *codegen) emitLoadConst(t types.TypeAndValue) { switch typ.Kind() { case types.Int, types.UntypedInt, types.Uint, + types.Int8, types.Uint8, types.Int16, types.Uint16, types.Int32, types.Uint32, types.Int64, types.Uint64: val, _ := constant.Int64Val(t.Value) @@ -143,10 +144,6 @@ func (c *codegen) emitLoadConst(t types.TypeAndValue) { case types.Bool, types.UntypedBool: val := constant.BoolVal(t.Value) emit.Bool(c.prog.BinWriter, val) - case types.Byte: - val, _ := constant.Int64Val(t.Value) - b := byte(val) - emit.Bytes(c.prog.BinWriter, []byte{b}) default: c.prog.Err = fmt.Errorf("compiler doesn't know how to convert this basic type: %v", t) return diff --git a/pkg/compiler/constant_test.go b/pkg/compiler/constant_test.go index 9608e4e9c..725ff1dba 100644 --- a/pkg/compiler/constant_test.go +++ b/pkg/compiler/constant_test.go @@ -36,6 +36,17 @@ func TestShortHandMultiConst(t *testing.T) { eval(t, src, big.NewInt(6)) } +func TestByteConstant(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/interop/convert" + const a byte = 0xFF + func Main() int64 { + x := convert.ToInteger(a) + return x+1 + }` + eval(t, src, big.NewInt(0x100)) +} + func TestGlobalsWithFunctionParams(t *testing.T) { src := ` package foobar