From 13136c5e4bc7674260905ae699d8f76c69f017cb Mon Sep 17 00:00:00 2001 From: Omar Sy Date: Tue, 26 Nov 2024 21:00:00 +0100 Subject: [PATCH] fix: test --- gnovm/pkg/gnolang/preprocess.go | 9 +++++++++ gnovm/tests/files/const30.gno | 2 +- gnovm/tests/files/const37_native.gno | 2 +- gnovm/tests/files/const38.gno | 8 ++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 9cacf7b60fa..a29e96cec02 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2436,6 +2436,15 @@ func parseAssignFromExprList( for i := 0; i < numNames; i++ { sts[i] = nt } + if isConst { + if xnt, ok := nt.(*NativeType); ok { + nt = go2GnoBaseType(xnt.Type) + } + + if _, ok := baseOf(nt).(PrimitiveType); !ok { + panic(fmt.Sprintf("invalid constant type %s", nt.String())) + } + } // Convert if const to nt. for i := range valueExprs { checkOrConvertType(store, bn, &valueExprs[i], nt, false) diff --git a/gnovm/tests/files/const30.gno b/gnovm/tests/files/const30.gno index 3908ee26ee3..4a166013cdc 100644 --- a/gnovm/tests/files/const30.gno +++ b/gnovm/tests/files/const30.gno @@ -12,4 +12,4 @@ func main() { } // Error: -// main/files/const30.gno:10:8: v() (no value) used as value +// main/files/const30.gno:10:8: v (no value) used as value diff --git a/gnovm/tests/files/const37_native.gno b/gnovm/tests/files/const37_native.gno index 413fa011151..6a164328a3b 100644 --- a/gnovm/tests/files/const37_native.gno +++ b/gnovm/tests/files/const37_native.gno @@ -7,4 +7,4 @@ func main() { } // Error: -// main/files/const37_native.gno:6:8: time.UTC (variable of type gonative{*time.Location}) is not constant \ No newline at end of file +// main/files/const37_native.gno:6:8: time.UTC (variable of type *time.Location) is not constant diff --git a/gnovm/tests/files/const38.gno b/gnovm/tests/files/const38.gno index 1aee945d434..57f0b64f74f 100644 --- a/gnovm/tests/files/const38.gno +++ b/gnovm/tests/files/const38.gno @@ -1,11 +1,11 @@ package main -import "net" +import "std" func main() { - v := net.TCPAddr{} - const c = v.IP + v := std.Coin{} + const c = v.Denom } // Error: -// main/files/const38.gno:7:8: v.IP (variable of type gonative{net.TCPAddr}) is not constant \ No newline at end of file +// main/files/const38.gno:7:8: v.Denom (variable of type std.Coin) is not constant