diff --git a/illegal/field_test.go b/illegal/field_test.go index ed978fe..32d1f65 100644 --- a/illegal/field_test.go +++ b/illegal/field_test.go @@ -14,8 +14,9 @@ func TestIllegalField(t *testing.T) { illegal.SetPrivateField(&s, "a", 10) illegal.SetPrivateField(&s, "b", "foo") + illegal.SetPrivateField(&s, "p", internal.NewPrivateType(42)) - assert.Equal(t, "10 foo", s.String()) + assert.Equal(t, "10 foo 42", s.String()) } func TestIllegalWrongFieldType(t *testing.T) { diff --git a/illegal/internal/struct.go b/illegal/internal/struct.go index c09a1b3..03469d7 100644 --- a/illegal/internal/struct.go +++ b/illegal/internal/struct.go @@ -4,11 +4,20 @@ package internal import "fmt" +type privateType struct { + x int +} + +func NewPrivateType(x int) any { + return privateType{x} +} + type Struct struct { a int b string + p privateType } func (s *Struct) String() string { - return fmt.Sprintf("%d %s", s.a, s.b) + return fmt.Sprintf("%d %s %d", s.a, s.b, s.p.x) }