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 #46731
This commit is contained in:
aimuz 2023-11-12 11:21:41 +08:00
parent 8da6405e0d
commit cd66b5a41b
No known key found for this signature in database
GPG Key ID: 63C3DC9FBA22D9D7
1 changed files with 6 additions and 10 deletions

View File

@ -2503,19 +2503,15 @@ func (c *declCollector) Visit(n syntax.Node) syntax.Visitor {
return c.withTParams(obj)
case *syntax.TypeDecl:
pw.checkPragmas(n.Pragma, 0, false)
obj := pw.info.Defs[n.Name].(*types2.TypeName)
d := typeDeclGen{TypeDecl: n, implicits: c.implicits}
if n.Alias {
pw.checkPragmas(n.Pragma, 0, false)
} else {
pw.checkPragmas(n.Pragma, 0, false)
// Assign a unique ID to function-scoped defined types.
if c.withinFunc {
*c.typegen++
d.gen = *c.typegen
}
// Assign a unique ID to function-scoped defined types.
if !n.Alias && c.withinFunc {
*c.typegen++
d.gen = *c.typegen
}
pw.typDecls[obj] = d