Skip to content

Commit cd66b5a

Browse files
committed
cmd/compile: streamline pragma checks for TypeDecl
Simplify the handling of pragmas in type declarations within noder/writer.go. Remove redundant checks by calling checkPragmas once at the beginning of case *syntax.TypeDecl and eliminate unnecessary else block. Also, ensure unique ID assignment for function-scoped defined types is only performed when n.Alias is false. Fixes a redundancy issue where pragma checks were performed inside both branches of an if-else statement unnecessarily. Update golang#46731
1 parent 8da6405 commit cd66b5a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/cmd/compile/internal/noder/writer.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -2503,19 +2503,15 @@ func (c *declCollector) Visit(n syntax.Node) syntax.Visitor {
25032503
return c.withTParams(obj)
25042504

25052505
case *syntax.TypeDecl:
2506+
pw.checkPragmas(n.Pragma, 0, false)
2507+
25062508
obj := pw.info.Defs[n.Name].(*types2.TypeName)
25072509
d := typeDeclGen{TypeDecl: n, implicits: c.implicits}
25082510

2509-
if n.Alias {
2510-
pw.checkPragmas(n.Pragma, 0, false)
2511-
} else {
2512-
pw.checkPragmas(n.Pragma, 0, false)
2513-
2514-
// Assign a unique ID to function-scoped defined types.
2515-
if c.withinFunc {
2516-
*c.typegen++
2517-
d.gen = *c.typegen
2518-
}
2511+
// Assign a unique ID to function-scoped defined types.
2512+
if !n.Alias && c.withinFunc {
2513+
*c.typegen++
2514+
d.gen = *c.typegen
25192515
}
25202516

25212517
pw.typDecls[obj] = d

0 commit comments

Comments
 (0)