fix: change to isStringPtrType for global string var
- Replace isStringType with isStringPtrType to properly validate that only *string type variables can be rewritten with -ldflags -X - Remove maxStringTypeDepth constant as it's no longer needed - Update tests to reflect the new function name and add test case for valid *string type - Fix compileGlobal to use gbl.Type() for accurate type checking This addresses the review feedback that Go only allows -X rewrites for the basic string type, not derived types like "type T string". Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: cpunion <8459+cpunion@users.noreply.github.com>
This commit is contained in:
@@ -95,21 +95,24 @@ func TestRewriteValueNoDot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStringTypeDefault(t *testing.T) {
|
||||
func TestIsStringPtrTypeDefault(t *testing.T) {
|
||||
ctx := &context{}
|
||||
if ctx.isStringType(types.NewPointer(types.Typ[types.Int])) {
|
||||
if ctx.isStringPtrType(types.NewPointer(types.Typ[types.Int])) {
|
||||
t.Fatalf("expected non-string pointer to return false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsStringTypeBranches(t *testing.T) {
|
||||
func TestIsStringPtrTypeBranches(t *testing.T) {
|
||||
ctx := &context{}
|
||||
if ctx.isStringType(types.NewSlice(types.Typ[types.String])) {
|
||||
if ctx.isStringPtrType(types.NewSlice(types.Typ[types.String])) {
|
||||
t.Fatalf("slice should trigger default branch and return false")
|
||||
}
|
||||
if ctx.isStringType(nil) {
|
||||
if ctx.isStringPtrType(nil) {
|
||||
t.Fatalf("nil type should return false")
|
||||
}
|
||||
if !ctx.isStringPtrType(types.NewPointer(types.Typ[types.String])) {
|
||||
t.Fatalf("*string should return true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteIgnoredInNonInitStore(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user