-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: fix type switch on arbitrary expressions
If the value on which to type-switch was already set (i.e. a variable), there was no problem. But if it had to be obtained through a complex expression (func call, array index, etc...), then the code to retrieve the value prior type-switch was not scheduled. This is now fixed. This issue is nasty because the behavior is silently changed, leading potentially to further unrelated issues or runtime panics. Fixes #1444.
- Loading branch information
Showing
3 changed files
with
42 additions
and
1 deletion.
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,17 @@ | ||
package main | ||
|
||
func f(params ...interface{}) { | ||
switch p0 := params[0].(type) { | ||
case string: | ||
println("string:", p0) | ||
default: | ||
println("not a string") | ||
} | ||
} | ||
|
||
func main() { | ||
f("Hello") | ||
} | ||
|
||
// Output: | ||
// string: Hello |
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,17 @@ | ||
package main | ||
|
||
func f(params ...interface{}) { | ||
switch params[0].(type) { | ||
case string: | ||
println("a string") | ||
default: | ||
println("not a string") | ||
} | ||
} | ||
|
||
func main() { | ||
f("Hello") | ||
} | ||
|
||
// Output: | ||
// a string |
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