cl: remove Underlying() call to reject string type aliases in rewrites
Type aliases like `type T string` are no longer supported for -ldflags -X rewrites. Only direct *string types are now allowed. - Removed Underlying() call from isStringPtrType - Added TestRewriteIgnoresStringAlias test case Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: cpunion <8459+cpunion@users.noreply.github.com>
This commit is contained in:
@@ -151,7 +151,7 @@ func (p *context) isStringPtrType(typ types.Type) bool {
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
basic, ok := ptr.Elem().Underlying().(*types.Basic)
|
||||
basic, ok := ptr.Elem().(*types.Basic)
|
||||
return ok && basic.Kind() == types.String
|
||||
}
|
||||
|
||||
|
||||
@@ -153,3 +153,17 @@ var VarStruct = wrapper{v: 1}
|
||||
t.Fatalf("non-string variables must not be rewritten:\n%s", ir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteIgnoresStringAlias(t *testing.T) {
|
||||
const src = `package rewritepkg
|
||||
type T string
|
||||
var VarAlias T = "original_value"
|
||||
`
|
||||
ir := compileWithRewrites(t, src, map[string]string{"VarAlias": "rewrite_alias"})
|
||||
if strings.Contains(ir, `c"rewrite_alias"`) {
|
||||
t.Fatalf("string alias types must not be rewritten:\n%s", ir)
|
||||
}
|
||||
if !strings.Contains(ir, `c"original_value"`) {
|
||||
t.Fatalf("original value should remain for alias type:\n%s", ir)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user