compiler: do not DROP return value with type assertion
The same problem as with IF. Example: ``` func foo() interface{} { ... } func Main() int{} { return foo().(int) <--- panic here } ```
This commit is contained in:
parent
dbce3c9a19
commit
f8d5c40928
2 changed files with 20 additions and 0 deletions
|
@ -123,3 +123,18 @@ func TestNamedReturn(t *testing.T) {
|
|||
t.Run("EmptyReturn", runCase("", big.NewInt(1), big.NewInt(2)))
|
||||
t.Run("AnotherVariable", runCase("b, c", big.NewInt(2), big.NewInt(3)))
|
||||
}
|
||||
|
||||
func TestTypeAssertReturn(t *testing.T) {
|
||||
src := `
|
||||
package main
|
||||
|
||||
func foo() interface{} {
|
||||
return 5
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
return foo().(int)
|
||||
}
|
||||
`
|
||||
eval(t, src, big.NewInt(5))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue