Closed zbysir closed 1 year ago
Additional Note:
Both of the following pieces of code work fine:
type A struct {
B *B[string]
}
type B[T any] struct {
data T
}
a := &A{
B: &B[string]{},
}
type A struct {
*B
}
type B struct {
}
a := &A{
B: &B{},
}
Maybe this "embedding" issue is related to https://github.com/traefik/yaegi/issues/1502
This can be quickly fixed by modifying the fieldName method:
func fieldName(n *node) string {
switch n.kind {
case selectorExpr:
return fieldName(n.child[1])
case starExpr:
return fieldName(n.child[0])
case identExpr:
return n.ident
+ case indexExpr:
+ return fieldName(n.child[0])
default:
return ""
}
}
But maybe this is not the most correct, because indexExpr seems to be the wrong kind.
Update: indexExpr
is correct because go/ast is defined that way.
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
0.15.1
Additional Notes
Cannot run embedded + generic code, although they work in isolation.