From 895089fbbc0915f6ac1e074b313dc6c2308ddee6 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 14:30:06 +0200 Subject: [PATCH 1/8] untyped to interface check --- gnovm/pkg/gnolang/preprocess.go | 1 + gnovm/tests/files/fun27.gno | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gnovm/tests/files/fun27.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 64fe1fbff45..e015c41251c 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2427,6 +2427,7 @@ func cmpSpecificity(t1, t2 Type) int { func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative bool) { if cx, ok := (*x).(*ConstExpr); ok { convertConst(store, last, cx, t) + checkType(cx.T, t, autoNative) } else if bx, ok := (*x).(*BinaryExpr); ok && (bx.Op == SHL || bx.Op == SHR) { // "push" expected type into shift binary's left operand. checkOrConvertType(store, last, &bx.Left, t, autoNative) diff --git a/gnovm/tests/files/fun27.gno b/gnovm/tests/files/fun27.gno new file mode 100644 index 00000000000..0ecfbfd69f0 --- /dev/null +++ b/gnovm/tests/files/fun27.gno @@ -0,0 +1,16 @@ +package main + +type Foo interface { + foo() +} + +func NewSet() Foo { + return 1 +} + +func main() { + NewSet() +} + +// Error: +// main/files/fun27.gno:9: int does not implement test.Foo From df7e7772197adf30f914d8939c4ee031471bdcab Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 14:38:49 +0200 Subject: [PATCH 2/8] save --- gnovm/pkg/gnolang/preprocess.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index e015c41251c..2383788c4a3 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2427,7 +2427,9 @@ func cmpSpecificity(t1, t2 Type) int { func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative bool) { if cx, ok := (*x).(*ConstExpr); ok { convertConst(store, last, cx, t) - checkType(cx.T, t, autoNative) + if t != nil { + checkType(cx.T, t, autoNative) + } } else if bx, ok := (*x).(*BinaryExpr); ok && (bx.Op == SHL || bx.Op == SHR) { // "push" expected type into shift binary's left operand. checkOrConvertType(store, last, &bx.Left, t, autoNative) From a6ebfddf766e146a0c55f0868a342e20bcb2fbf2 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 15:47:22 +0200 Subject: [PATCH 3/8] save --- gnovm/pkg/gnolang/preprocess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 2383788c4a3..60b5bc6ff5a 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2427,7 +2427,7 @@ func cmpSpecificity(t1, t2 Type) int { func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative bool) { if cx, ok := (*x).(*ConstExpr); ok { convertConst(store, last, cx, t) - if t != nil { + if cx.T != nil && t != nil { checkType(cx.T, t, autoNative) } } else if bx, ok := (*x).(*BinaryExpr); ok && (bx.Op == SHL || bx.Op == SHR) { From 0e33599c34fccd6513b7d909ec7d64d284f69597 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 17:13:03 +0200 Subject: [PATCH 4/8] save --- gnovm/pkg/gnolang/preprocess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 60b5bc6ff5a..e9281d3463d 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2636,7 +2636,7 @@ func checkType(xt Type, dt Type, autoNative bool) { switch dt.Kind() { case IntKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, UintKind, Uint8Kind, Uint16Kind, - Uint32Kind, Uint64Kind: + Uint32Kind, Uint64Kind, BigintKind: return // ok default: panic(fmt.Sprintf( From 0a5774f779115434d4f46ed6a0cc46d7d7be40b5 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 17:46:54 +0200 Subject: [PATCH 5/8] save --- gnovm/pkg/gnolang/preprocess.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index e9281d3463d..eaca152bd0f 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2427,9 +2427,6 @@ func cmpSpecificity(t1, t2 Type) int { func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative bool) { if cx, ok := (*x).(*ConstExpr); ok { convertConst(store, last, cx, t) - if cx.T != nil && t != nil { - checkType(cx.T, t, autoNative) - } } else if bx, ok := (*x).(*BinaryExpr); ok && (bx.Op == SHL || bx.Op == SHR) { // "push" expected type into shift binary's left operand. checkOrConvertType(store, last, &bx.Left, t, autoNative) @@ -2475,6 +2472,9 @@ func convertIfConst(store Store, last BlockNode, x Expr) { func convertConst(store Store, last BlockNode, cx *ConstExpr, t Type) { if t != nil && t.Kind() == InterfaceKind { + if cx.T != nil && t != nil { + checkType(cx.T, t, false) + } t = nil // signifies to convert to default type. } if isUntyped(cx.T) { From 3a5d22de2b345a3d0ee50b16922ea295c03eb69e Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 18:51:33 +0200 Subject: [PATCH 6/8] save --- gnovm/tests/files/fun27.gno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/tests/files/fun27.gno b/gnovm/tests/files/fun27.gno index 0ecfbfd69f0..4e6e25e1065 100644 --- a/gnovm/tests/files/fun27.gno +++ b/gnovm/tests/files/fun27.gno @@ -13,4 +13,4 @@ func main() { } // Error: -// main/files/fun27.gno:9: int does not implement test.Foo +// main/files/fun27.gno:8: bigint does not implement main.Foo From fd31cd77ae10a9b578da7d7cd945b9eaf7572da1 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Mon, 6 May 2024 19:03:47 +0200 Subject: [PATCH 7/8] save --- gnovm/pkg/gnolang/preprocess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index eaca152bd0f..69458b9d8ac 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2636,7 +2636,7 @@ func checkType(xt Type, dt Type, autoNative bool) { switch dt.Kind() { case IntKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, UintKind, Uint8Kind, Uint16Kind, - Uint32Kind, Uint64Kind, BigintKind: + Uint32Kind, Uint64Kind: return // ok default: panic(fmt.Sprintf( From b3ef53434c86786c897edc9fe58fd35e7747c091 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Tue, 7 May 2024 01:09:44 +0200 Subject: [PATCH 8/8] Update gnovm/pkg/gnolang/preprocess.go Co-authored-by: deelawn --- gnovm/pkg/gnolang/preprocess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 69458b9d8ac..12cf78cb7fa 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -2472,7 +2472,7 @@ func convertIfConst(store Store, last BlockNode, x Expr) { func convertConst(store Store, last BlockNode, cx *ConstExpr, t Type) { if t != nil && t.Kind() == InterfaceKind { - if cx.T != nil && t != nil { + if cx.T != nil { checkType(cx.T, t, false) } t = nil // signifies to convert to default type.