Skip to content

Commit

Permalink
Consider receivers as vars when generating func/closure types
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Dec 14, 2023
1 parent 67101be commit d85e5f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 13 additions & 1 deletion compiler/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func collectFunctypes(p *packages.Package, name string, fn ast.Node, scope *func
signature := copyFunctionType(functionTypeOf(fn))
signature.TypeParams = nil

for _, fields := range []*ast.FieldList{signature.Params, signature.Results} {
recv := copyFieldList(functionRecvOf(fn))
for _, fields := range []*ast.FieldList{recv, signature.Params, signature.Results} {
if fields != nil {
for _, field := range fields.List {
for _, name := range field.Names {
Expand Down Expand Up @@ -348,6 +349,17 @@ func functionTypeOf(fn ast.Node) *ast.FuncType {
}
}

func functionRecvOf(fn ast.Node) *ast.FieldList {
switch f := fn.(type) {
case *ast.FuncDecl:
return f.Recv
case *ast.FuncLit:
return nil
default:
panic("node is neither *ast.FuncDecl or *ast.FuncLit")
}
}

func copyFunctionType(f *ast.FuncType) *ast.FuncType {
return &ast.FuncType{
TypeParams: copyFieldList(f.TypeParams),
Expand Down
3 changes: 2 additions & 1 deletion compiler/testdata/coroutine_durable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3360,7 +3360,8 @@ func init() {
_types.RegisterClosure[func(x int), struct {
F uintptr
D uintptr
X0 int
X0 *IdentityGenericStruct[T]

Check failure on line 3363 in compiler/testdata/coroutine_durable.go

View workflow job for this annotation

GitHub Actions / Test

undefined: T
X1 int
}]("github.com/stealthrocket/coroutine/compiler/testdata.(*IdentityGenericStruct[go.shape.int]).Closure.func1")
_types.RegisterFunc[func()]("github.com/stealthrocket/coroutine/compiler/testdata.(*IdentityGenericStruct[go.shape.int]).Run")
_types.RegisterFunc[func(n int)]("github.com/stealthrocket/coroutine/compiler/testdata.Double")
Expand Down

0 comments on commit d85e5f8

Please sign in to comment.