traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
6.94k stars 343 forks source link

Type checking does not work as expected #1483

Closed brucengdev closed 1 year ago

brucengdev commented 1 year ago

The following program sample.go triggers an unexpected result

package main

import (
    "encoding/json"
    "fmt"
)

func main() {
    jsonString := `{"MyField":[1,2,3,4]}`

    var parsed map[string]interface{}
    json.Unmarshal([]byte(jsonString), &parsed)

    switch parsed["MyField"].(type) {
    case []interface{}:
        fmt.Println("MyField is an array")
    default:
        fmt.Println("Didn't match any type")
    }
}

Expected result

MyField is an array

Got

Didn't match any type

Yaegi Version

v0.10.0

Additional Notes

No response

mvertes commented 1 year ago

Testing it with last version v0.14.3 works. Please upgrade.