From 8e45511bc4735cc67bdfe5631edf98513733a0b3 Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Sun, 23 Apr 2023 14:55:18 +0400 Subject: [PATCH] [illegal] Add field with private type --- illegal/field_test.go | 3 ++- illegal/internal/struct.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) 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) }