Skip to content

Commit

Permalink
Merge pull request #1571 from visualfc/types_funlit
Browse files Browse the repository at this point in the history
cl: types record funlit
  • Loading branch information
xushiwei committed Dec 10, 2023
2 parents e0e9184 + 22ccdae commit 34f786e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ func compileFuncLit(ctx *blockCtx, v *ast.FuncLit) {
cb := ctx.cb
comments, once := cb.BackupComments()
sig := toFuncType(ctx, v.Type, nil, nil)
if rec := ctx.recorder(); rec != nil {
rec.recordFuncLit(ctx, v, sig)
}
fn := cb.NewClosureWith(sig)
if body := v.Body; body != nil {
loadFuncBody(ctx, fn, body, v)
Expand Down
5 changes: 5 additions & 0 deletions cl/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (rec *typesRecorder) recordCompositeLit(ctx *blockCtx, v *ast.CompositeLit,
rec.Type(v, typesutil.NewTypeAndValueForValue(typ, nil, typesutil.Value))
}

func (rec *typesRecorder) recordFuncLit(ctx *blockCtx, v *ast.FuncLit, typ types.Type) {
rec.Type(v.Type, typesutil.NewTypeAndValueForType(typ))
rec.Type(v, typesutil.NewTypeAndValueForValue(typ, nil, typesutil.Value))
}

func (rec *typesRecorder) recordType(ctx *blockCtx, typ ast.Expr, t types.Type) {
rec.Type(typ, typesutil.NewTypeAndValueForType(t))
}
Expand Down
15 changes: 15 additions & 0 deletions x/typesutil/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,18 @@ func test() {
}
`)
}

func TestFuncLit(t *testing.T) {
testInfo(t, `package main
func test() {
add := func(n1 int, n2 int) int {
return n1+n2
}
_ = add(1,2)
go func(n int) {
_ = n+100
}(100)
}
`)
}

0 comments on commit 34f786e

Please sign in to comment.