diff --git a/package.go b/package.go index bc25786ce..6b4e3bd0d 100644 --- a/package.go +++ b/package.go @@ -5,6 +5,7 @@ import ( "go/token" "reflect" "strconv" + "strings" ) // PackageDefinitions files and definition in a package. @@ -94,6 +95,10 @@ func (pkg *PackageDefinitions) evaluateConstValue(file *ast.File, iota int, expr case *ast.BasicLit: switch valueExpr.Kind { case token.INT: + // handle underscored number, such as 1_000_000 + if strings.ContainsRune(valueExpr.Value, '_') { + valueExpr.Value = strings.Replace(valueExpr.Value, "_", "", -1) + } // hexadecimal if len(valueExpr.Value) > 2 && valueExpr.Value[0] == '0' && valueExpr.Value[1] == 'x' { if x, err := strconv.ParseInt(valueExpr.Value[2:], 16, 64); err == nil { diff --git a/testdata/enums/consts/const.go b/testdata/enums/consts/const.go index 83dc97fa7..27bfb28f5 100644 --- a/testdata/enums/consts/const.go +++ b/testdata/enums/consts/const.go @@ -10,3 +10,4 @@ const octnum = 017 const nonescapestr = `aa\nbb\u8888cc` const escapestr = "aa\nbb\u8888cc" const escapechar = '\u8888' +const underscored = 1_000_000