Skip to content

Commit

Permalink
feat(gnovm): sync code AssignStmt - ValueDecl (#3017)
Browse files Browse the repository at this point in the history
This PR aims at fixing this issue
[1958](#1958)

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
</details>

---------

Co-authored-by: hieu.ha <[email protected]>
Co-authored-by: Mikael VALLENET <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent 7718bc3 commit dc65f91
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 192 deletions.
407 changes: 215 additions & 192 deletions gnovm/pkg/gnolang/preprocess.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions gnovm/tests/files/assign25c.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "fmt"

func f() (a, b int) {
return 1, 2
}

func main() {
x, y, z := 1, f()
fmt.Println(x, y, z)
}

// Error:
// main/files/assign25c.gno:10:2: assignment mismatch: 3 variable(s) but 2 value(s)
15 changes: 15 additions & 0 deletions gnovm/tests/files/assign25d.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "fmt"

func f() (a, b int) {
return 1, 2
}

func main() {
x, y, z := f(), 1, 2, 3
fmt.Println(x, y, z)
}

// Error:
// main/files/assign25d.gno:10:2: assignment mismatch: 3 variable(s) but 4 value(s)
22 changes: 22 additions & 0 deletions gnovm/tests/files/assign32.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

func foo() int {
return 2
}

func main() {
var mp map[string]int = map[string]int{"idx": 4}
var sl []int = []int{4, 5, 6}
arr := [1]int{7}
var num interface{} = 5

a, b, c, d, e, f, g := int(1), foo(), 3, mp["idx"], num.(int), sl[2], arr[0]
println(a, b, c, d, e, f, g)

var h, i, j, k, l, m, n int = int(1), foo(), 3, mp["idx"], num.(int), sl[2], arr[0]
println(h, i, j, k, l, m, n)
}

// Output:
// 1 2 3 4 5 6 7
// 1 2 3 4 5 6 7
13 changes: 13 additions & 0 deletions gnovm/tests/files/assign33.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

func foo() (int, bool) {
return 1, true
}

func main() {
var a, b int = foo()
println(a, b)
}

// Error:
// main/files/assign33.gno:8:6: cannot use foo<VPBlock(3,0)>() (value of type bool) as int value in assignment
14 changes: 14 additions & 0 deletions gnovm/tests/files/assign34.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

func foo() (int, bool) {
return 1, true
}

func main() {
var a, b = foo()
println(a, b)
}

// Output:
// 1 true

14 changes: 14 additions & 0 deletions gnovm/tests/files/assign35.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

func foo() (int, bool) {
return 1, true
}

func main() {
a, b := 2, foo()

println(a, b)
}

// Error:
// main/files/assign35.gno:8:2: multiple-value foo<VPBlock(3,0)> (value of type [int bool]) in single-value context
19 changes: 19 additions & 0 deletions gnovm/tests/files/assign36.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import "fmt"

func f() (int) {
return 2
}

func main() {
var a, b, c = 1, f(), 3
fmt.Println(a, b, c)

x, y, z := 1, f(), 3
fmt.Println(x, y, z)
}

// Output:
// 1 2 3
// 1 2 3
15 changes: 15 additions & 0 deletions gnovm/tests/files/var22c.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import "fmt"

func f() (a, b int) {
return 1, 2
}

func main() {
var x, y, z = 1, f()
fmt.Println(x, y, z)
}

// Error:
// main/files/var22c.gno:10:6: missing init expr for z<!VPUverse(0)>

0 comments on commit dc65f91

Please sign in to comment.