diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 6b77f5562a0..f4a42e1e583 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -958,6 +958,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { } n.NumArgs = 1 if arg0, ok := n.Args[0].(*ConstExpr); ok { + var constConverted bool ct := evalStaticType(store, last, n.Func) // As a special case, if a decimal cannot // be represented as an integer, it cannot be converted to one, @@ -974,10 +975,17 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { arg0)) } } + + convertConst(store, last, arg0, ct) + constConverted = true } + // (const) untyped decimal -> float64. // (const) untyped bigint -> int. - convertConst(store, last, arg0, nil) + if !constConverted { + convertConst(store, last, arg0, nil) + } + // evaluate the new expression. cx := evalConst(store, last, n) // Though cx may be undefined if ct is interface, diff --git a/gnovm/tests/files/issue-1085.gno b/gnovm/tests/files/issue-1085.gno new file mode 100644 index 00000000000..680eb8a413e --- /dev/null +++ b/gnovm/tests/files/issue-1085.gno @@ -0,0 +1,20 @@ +package main + +func main() { + a := uint64(9223372036854775808) + var b uint64 = uint64(9223372036854775808) + + const c = uint64(9223372036854775808) + const d uint64 = uint64(9223372036854775808) + + println(a) + println(b) + println(c) + println(d) +} + +// Output: +// 9223372036854775808 +// 9223372036854775808 +// 9223372036854775808 +// 9223372036854775808