Skip to content

Commit

Permalink
Merge pull request #1597 from xushiwei/emb
Browse files Browse the repository at this point in the history
support var document (eg. //go:embed)
  • Loading branch information
xushiwei committed Jan 6, 2024
2 parents d6b48e1 + 713ffd6 commit 7b32e03
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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

0 comments on commit 7b32e03

Please sign in to comment.