From cd66b5a41bc08f13bd2f5c8ff589ed2db5c735cf Mon Sep 17 00:00:00 2001 From: aimuz Date: Sun, 12 Nov 2023 11:21:41 +0800 Subject: [PATCH] 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 --- src/cmd/compile/internal/noder/writer.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go index d75caf064a99b8..5ace705e20ae75 100644 --- a/src/cmd/compile/internal/noder/writer.go +++ b/src/cmd/compile/internal/noder/writer.go @@ -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