mirror of
https://github.com/traefik/yaegi.git
synced 2026-06-01 18:37:56 +00:00
Although empty interfaces are usually not wrapped, for compatibility with the runtime, we may have to wrap them sometime into `valueInterface` type. It allows to preserve interpreter type metadata for interface values exchanged with the runtime. It is necessary to resolve methods and receivers in the absence of reflect support. During type assertions on empty interfaces, we now handle a possible valueInterface and dereference the original value to pursue the type assertion. In the same change, we have improved the format of some panic messages at runtime to give location of offending source at interpreter level. This change will allow to fix traefik/traefik#9362.
49 lines
760 B
Go
49 lines
760 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
func main() {
|
|
assertInt()
|
|
assertNil()
|
|
assertValue()
|
|
}
|
|
|
|
func assertInt() {
|
|
defer func() {
|
|
r := recover()
|
|
fmt.Println(r)
|
|
}()
|
|
|
|
var v interface{} = 1
|
|
println(v.(string))
|
|
}
|
|
|
|
func assertNil() {
|
|
defer func() {
|
|
r := recover()
|
|
fmt.Println(r)
|
|
}()
|
|
|
|
var v interface{}
|
|
println(v.(string))
|
|
}
|
|
|
|
func assertValue() {
|
|
defer func() {
|
|
r := recover()
|
|
fmt.Println(r)
|
|
}()
|
|
|
|
var v http.ResponseWriter = httptest.NewRecorder()
|
|
println(v.(http.Pusher))
|
|
}
|
|
|
|
// Output:
|
|
// 22:10: interface conversion: interface {} is int, not string
|
|
// 32:10: interface conversion: interface {} is nil, not string
|
|
// 42:10: interface conversion: *httptest.ResponseRecorder is not http.Pusher: missing method Push
|