mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
reflect: don't construct an interface-in-interface value
v.Interaface() could construct an interface in interface value if v was of type interface. This is not correct, and doesn't follow upstream Go behavior. Instead, it should return the interface value itself.
This commit is contained in:
committed by
Ron Evans
parent
b534dd67e0
commit
d15e32fb89
Vendored
+16
@@ -321,6 +321,9 @@ func main() {
|
||||
|
||||
println("\nstruct tags")
|
||||
TestStructTag()
|
||||
|
||||
println("\nv.Interface() method")
|
||||
testInterfaceMethod()
|
||||
}
|
||||
|
||||
func emptyFunc() {
|
||||
@@ -470,6 +473,19 @@ func TestStructTag() {
|
||||
println(field.Tag.Get("color"), field.Tag.Get("species"))
|
||||
}
|
||||
|
||||
// Test Interface() call: it should never return an interface itself.
|
||||
func testInterfaceMethod() {
|
||||
v := reflect.ValueOf(struct{ X interface{} }{X: 5})
|
||||
println("kind:", v.Field(0).Kind().String())
|
||||
itf := v.Field(0).Interface()
|
||||
switch n := itf.(type) {
|
||||
case int:
|
||||
println("int", n) // correct
|
||||
default:
|
||||
println("something else") // incorrect
|
||||
}
|
||||
}
|
||||
|
||||
var xorshift32State uint32 = 1
|
||||
|
||||
func xorshift32(x uint32) uint32 {
|
||||
|
||||
Reference in New Issue
Block a user