[illegal] Add field with private type
This commit is contained in:
parent
11277ded5b
commit
8e45511bc4
2 changed files with 12 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue