-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: fix redeclarations containing a blank variable
In [short variable declarations](https://go.dev/ref/spec#Short_variable_declarations), The reuse of existing symbols is possible only if a new variable is defined, otherwise a new symbol must be created, which was not the case in the issue. Search for new symbols and correctly ignore blank variables. Fixes #1434.
- Loading branch information
Showing
4 changed files
with
79 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
func main() { | ||
s := make([]map[string]string, 0) | ||
m := make(map[string]string) | ||
m["m1"] = "m1" | ||
m["m2"] = "m2" | ||
s = append(s, m) | ||
tmpStr := "start" | ||
println(tmpStr) | ||
for _, v := range s { | ||
tmpStr, ok := v["m1"] | ||
println(tmpStr, ok) | ||
} | ||
println(tmpStr) | ||
} | ||
|
||
// Output: | ||
// start | ||
// m1 true | ||
// start |
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,21 @@ | ||
package main | ||
|
||
func main() { | ||
s := make([]map[string]string, 0) | ||
m := make(map[string]string) | ||
m["m1"] = "m1" | ||
m["m2"] = "m2" | ||
s = append(s, m) | ||
tmpStr := "start" | ||
println(tmpStr) | ||
for _, v := range s { | ||
tmpStr, _ := v["m1"] | ||
println(tmpStr) | ||
} | ||
println(tmpStr) | ||
} | ||
|
||
// Output: | ||
// start | ||
// m1 | ||
// start |
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