Skip to content

Commit

Permalink
Use doc.IsPredeclared() for codegen.fixReservedGo()
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed Oct 4, 2024
1 parent 0f727e1 commit 4ac46cc
Showing 1 changed file with 2 additions and 69 deletions.
71 changes: 2 additions & 69 deletions codegen/goify.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package codegen

import (
"go/doc"
"strings"

"goa.design/goa/v3/expr"
Expand Down Expand Up @@ -54,76 +55,8 @@ func UnionValTypeName(unionName string) string {

// fixReservedGo appends an underscore on to Go reserved keywords.
func fixReservedGo(w string) string {
if reservedGo[w] {
if doc.IsPredeclared(w) {
w += "_"
}
return w
}

var (
// reserved golang keywords and package names
reservedGo = map[string]bool{
// predeclared types
"bool": true,
"byte": true,
"complex128": true,
"complex64": true,
"float32": true,
"float64": true,
"int": true,
"int16": true,
"int32": true,
"int64": true,
"int8": true,
"rune": true,
"string": true,
"uint": true,
"uint16": true,
"uint32": true,
"uint64": true,
"uint8": true,
"uintptr": true,

// reserved keywords
"break": true,
"case": true,
"chan": true,
"const": true,
"continue": true,
"default": true,
"defer": true,
"delete": true,
"else": true,
"fallthrough": true,
"for": true,
"func": true,
"go": true,
"goto": true,
"if": true,
"import": true,
"interface": true,
"map": true,
"package": true,
"range": true,
"return": true,
"select": true,
"struct": true,
"switch": true,
"type": true,
"var": true,

// predeclared constants
"true": true,
"false": true,
"iota": true,
"nil": true,

// stdlib and goa packages used by generated code
"fmt": true,
"http": true,
"json": true,
"os": true,
"url": true,
"time": true,
}
)

0 comments on commit 4ac46cc

Please sign in to comment.