Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeswitch of an expression #1444

Closed
mvertes opened this issue Aug 24, 2022 · 0 comments · Fixed by #1445
Closed

typeswitch of an expression #1444

mvertes opened this issue Aug 24, 2022 · 0 comments · Fixed by #1445
Labels
area/core bug Something isn't working

Comments

@mvertes
Copy link
Member

mvertes commented Aug 24, 2022

The following program sample.go triggers an unexpected result

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")
}

Expected result

$ go run ./sample.go
Hello

Got

$ yaegi ./sample.go
not a string

Yaegi Version

v0.14.1

Additional Notes

This issue is related to #1426.

@mvertes mvertes added bug Something isn't working area/core labels Aug 24, 2022
mvertes added a commit to mvertes/yaegi that referenced this issue Aug 24, 2022
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.

The issue it fixes is nasty because the behavior was silently changed,
leading to further unrelated issues or panics.

Fixes traefik#1444.
traefiker pushed a commit to mvertes/yaegi that referenced this issue Aug 25, 2022
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.

The issue it fixes is nasty because the behavior was silently changed,
leading to further unrelated issues or panics.

Fixes traefik#1444.
traefiker pushed a commit that referenced this issue Aug 25, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant