forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): fix issue with locally re-definition (gnolang#3014)
closes: gnolang#3013 <!-- 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: Morgan Bazalgette <[email protected]>
- Loading branch information
1 parent
520195e
commit 287c22e
Showing
7 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
var ss = []int{1, 2, 3} | ||
|
||
func main() { | ||
for _, s := range ss { | ||
s := s | ||
println(s) | ||
} | ||
} | ||
|
||
// Output: | ||
// 1 | ||
// 2 | ||
// 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
var testTable = []struct { | ||
name string | ||
}{ | ||
{ | ||
"one", | ||
}, | ||
{ | ||
"two", | ||
}, | ||
} | ||
|
||
func main() { | ||
|
||
for _, testCase := range testTable { | ||
testCase := testCase | ||
|
||
println(testCase.name) | ||
} | ||
} | ||
|
||
// Output: | ||
// one | ||
// two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
func main() { | ||
for i := 0; i < 3; i++ { | ||
i := i | ||
println(i) | ||
} | ||
} | ||
|
||
// Output: | ||
// 0 | ||
// 1 | ||
// 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
func main() { | ||
a := 1 | ||
b := 3 | ||
println(a, b) // prints 1 3 | ||
|
||
// Re-declaration of 'a' is allowed because 'c' is a new variable | ||
a, c := 2, 5 | ||
println(a, c) // prints 2 5 | ||
} | ||
|
||
// Output: | ||
// 1 3 | ||
// 2 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
func main() { | ||
a := 1 | ||
println(a) // prints 1 | ||
|
||
if true { | ||
a := 2 // valid: new scope inside the if statement | ||
println(a) // prints 2 | ||
} | ||
|
||
println(a) // prints 1: outer variable is unchanged | ||
} | ||
|
||
// Output: | ||
// 1 | ||
// 2 | ||
// 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
func main() { | ||
a, b := 1, 2 | ||
a, b := 3, 4 | ||
} | ||
|
||
// Error: | ||
// files/redefine6.gno:5:2: no new variables on left side of := |