Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toStructType: add field pos and record.Def field #1496

Merged
merged 4 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ func loadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool) {
}
}
sig := toFuncType(ctx, d.Type, recv, d)
fn, err := ctx.pkg.NewFuncWith(d.Pos(), name, sig, func() token.Pos {
fn, err := ctx.pkg.NewFuncWith(d.Name.Pos(), name, sig, func() token.Pos {
return d.Recv.List[0].Type.Pos()
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cl/error_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ for _, a = range b {

func TestErrInitFunc(t *testing.T) {
codeErrorTest(t,
`./bar.gop:2:1: func init must have no arguments and no return values`, `
`./bar.gop:2:6: func init must have no arguments and no return values`, `
func init(v byte) {
}
`)
Expand Down
12 changes: 10 additions & 2 deletions cl/func_type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
if t, ok := typ.(*types.Named); ok { // #1196: embedded type should ensure loaded
ctx.loadNamed(ctx.pkg, t)
}
fld := types.NewField(token.NoPos, pkg, name, typ, true)
fld := types.NewField(field.Type.Pos(), pkg, name, typ, true)
if rec := ctx.recorder(); rec != nil {
if ident := parseTypeEmbedName(field.Type); ident != nil {
rec.Def(ident, fld)
}
}
fields = append(fields, fld)
tags = append(tags, toFieldTag(field.Tag))
continue
Expand All @@ -328,7 +333,10 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
if chk.chkRedecl(ctx, name.Name, name.NamePos) {
continue
}
fld := types.NewField(token.NoPos, pkg, name.Name, typ, false)
fld := types.NewField(name.Pos(), pkg, name.Name, typ, false)
if rec := ctx.recorder(); rec != nil {
rec.Def(name, fld)
}
fields = append(fields, fld)
tags = append(tags, toFieldTag(field.Tag))
}
Expand Down
2 changes: 1 addition & 1 deletion cl/outline/cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func preloadFunc(ctx *blockCtx, recv *types.Var, d *ast.FuncDecl, genBody bool)
}
}
sig := toFuncType(ctx, d.Type, recv, d)
fn, err := ctx.pkg.NewFuncWith(d.Pos(), name, sig, func() token.Pos {
fn, err := ctx.pkg.NewFuncWith(d.Name.Pos(), name, sig, func() token.Pos {
return d.Recv.List[0].Type.Pos()
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cl/outline/cl/error_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ for _, a = range b {

func TestErrInitFunc(t *testing.T) {
codeErrorTest(t,
`./bar.gop:2:1: func init must have no arguments and no return values`, `
`./bar.gop:2:6: func init must have no arguments and no return values`, `
func init(v byte) {
}
`)
Expand Down
4 changes: 2 additions & 2 deletions cl/outline/cl/func_type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
if chk.chkRedecl(ctx, name, field.Type.Pos()) {
continue
}
fld := types.NewField(token.NoPos, pkg, name, typ, true)
fld := types.NewField(field.Type.Pos(), pkg, name, typ, true)
fields = append(fields, fld)
tags = append(tags, toFieldTag(field.Tag))
continue
Expand All @@ -294,7 +294,7 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
if chk.chkRedecl(ctx, name.Name, name.NamePos) {
continue
}
fld := types.NewField(token.NoPos, pkg, name.Name, typ, false)
fld := types.NewField(name.Pos(), pkg, name.Name, typ, false)
fields = append(fields, fld)
tags = append(tags, toFieldTag(field.Tag))
}
Expand Down