Skip to content

Commit

Permalink
fix: verify type is ok
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed May 26, 2024
1 parent e1b0dc0 commit b436f3a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
tvs := make([]TypedValue, numNames)
if numNames > 1 && len(n.Values) == 1 {
// special case if `var a, b, c T? = f()` form.
cx := n.Values[0].(*CallExpr)
cx, ok := n.Values[0].(*CallExpr)
if !ok {
panic("should not happen")

Check warning on line 1862 in gnovm/pkg/gnolang/preprocess.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/preprocess.go#L1860-L1862

Added lines #L1860 - L1862 were not covered by tests
}
tt := evalStaticTypeOfRaw(store, last, cx).(*tupleType)
if len(tt.Elts) != numNames {
panic("should not happen")
Expand Down
11 changes: 11 additions & 0 deletions gnovm/tests/files/var18.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

func main() {
var a, b = 1
}

// Error:
// main/files/var18.gno:3: should not happen:
// --- preprocess stack ---
// stack 0: func main() { var a<VPBlock(1,0)>, b<VPBlock(1,1)> = (const (1 <untyped> bigint)) }
// ------------------------
11 changes: 11 additions & 0 deletions gnovm/tests/files/var19.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

func main() {
var a, b, c = 1, a+1
println(a)
println(b)
println(c)
}

// Error:
// main/files/var19.gno:3: constant definition loop with a
15 changes: 15 additions & 0 deletions gnovm/tests/files/var20.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

func r() int {
return 1
}

func main() {
var a, b, c = r()
}

// Error:
// main/files/var20.gno:7: should not happen:
// --- preprocess stack ---
// stack 0: func main() { var a<VPBlock(1,0)>, b<VPBlock(1,1)>, c<VPBlock(1,2)> = r<VPBlock(3,0)>() }
// ------------------------

0 comments on commit b436f3a

Please sign in to comment.