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

support var document (eg. //go:embed) #1597

Merged
merged 1 commit into from
Jan 6, 2024
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
7 changes: 4 additions & 3 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ func preloadFile(p *gox.Package, ctx *blockCtx, file string, f *ast.File, gopFil
vSpec = nil
old, _ := p.SetCurFile(goFile, true)
defer p.RestoreCurFile(old)
loadVars(ctx, v, true)
loadVars(ctx, v, d.Doc, true)
removeNames(syms, v.Names)
}
})
Expand Down Expand Up @@ -1224,7 +1224,7 @@ func loadConsts(ctx *blockCtx, cdecl *gox.ConstDefs, v *ast.ValueSpec, iotav int
defNames(ctx, v.Names, nil)
}

func loadVars(ctx *blockCtx, v *ast.ValueSpec, global bool) {
func loadVars(ctx *blockCtx, v *ast.ValueSpec, doc *ast.CommentGroup, global bool) {
var typ types.Type
if v.Type != nil {
typ = toType(ctx, v.Type)
Expand All @@ -1239,7 +1239,8 @@ func loadVars(ctx *blockCtx, v *ast.ValueSpec, global bool) {
} else {
scope = ctx.cb.Scope()
}
varDecl := ctx.pkg.NewVarEx(scope, v.Names[0].Pos(), typ, names...)
varDefs := ctx.pkg.NewVarDefs(scope).SetComments(doc)
varDecl := varDefs.New(v.Names[0].Pos(), typ, names...)
if nv := len(v.Values); nv > 0 {
cb := varDecl.InitStart(ctx.pkg)
if enableRecover {
Expand Down
2 changes: 1 addition & 1 deletion cl/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ func compileDeclStmt(ctx *blockCtx, expr *ast.DeclStmt) {
case token.VAR:
for _, spec := range d.Specs {
v := spec.(*ast.ValueSpec)
loadVars(ctx, v, false)
loadVars(ctx, v, d.Doc, false)
}
default:
log.Panicln("TODO: compileDeclStmt - unknown")
Expand Down