diff --git a/internal/literals/literals.go b/internal/literals/literals.go index 9ed5bdc..8f3b722 100644 --- a/internal/literals/literals.go +++ b/internal/literals/literals.go @@ -51,14 +51,8 @@ func Obfuscate(file *ast.File, info *types.Info, fset *token.FileSet, ignoreObj for _, name := range spec.Names { obj := info.ObjectOf(name) - basic, ok := obj.Type().(*types.Basic) - if !ok { - // skip the block if it contains non basic types - return false - } - - if basic.Info()&types.IsUntyped != 0 { - // skip the block if it contains untyped constants + // We only obfuscate const declarations with typed string values. + if obj.Type() != types.Typ[types.String] { return false } diff --git a/testdata/scripts/literals.txt b/testdata/scripts/literals.txt index fcc3b08..97dc18d 100644 --- a/testdata/scripts/literals.txt +++ b/testdata/scripts/literals.txt @@ -88,6 +88,11 @@ const ( skip2 = "also skip this" ) +// We used to conver this to a var in an attempt of obfuscating the literal. +// That would break the iota, which only works inside const declarations. +// We only obfuscate constant declarations with string values, anyway. +const fooTyped uint64 = 1 << iota + const arrayLen = 4 var array [arrayLen]byte