Skip to content

Commit

Permalink
Handle *types.Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Dec 16, 2023
1 parent 9c73432 commit 7ebbe1a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compiler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ func typeExpr(p *packages.Package, typ types.Type, typeArg func(*types.TypeParam
if t.Empty() {
return ast.NewIdent("any")
}
if t.NumEmbeddeds() > 0 {
panic("not implemented: interface with embeddeds")
}
methods := make([]*ast.Field, t.NumExplicitMethods())
for i := range methods {
m := t.ExplicitMethod(i)
methods[i] = &ast.Field{
Names: []*ast.Ident{ast.NewIdent(m.Name())},
Type: typeExpr(p, m.Type(), typeArg),
}
}
return &ast.InterfaceType{
Methods: &ast.FieldList{List: methods},
}
case *types.Signature:
return newFuncType(p, t, typeArg)
case *types.Named:
Expand Down Expand Up @@ -165,6 +179,10 @@ func substituteTypeArgs(p *packages.Package, expr ast.Expr, typeArg func(*types.
return &ast.StructType{
Fields: substituteFieldList(p, e.Fields, typeArg),
}
case *ast.InterfaceType:
return &ast.InterfaceType{
Methods: substituteFieldList(p, e.Methods, typeArg),
}
case *ast.StarExpr:
return &ast.StarExpr{
X: substituteTypeArgs(p, e.X, typeArg),
Expand Down

0 comments on commit 7ebbe1a

Please sign in to comment.