Skip to content

Commit 33b58a0

Browse files
committed
Add more tests that BigGo reflect tests
1 parent dbd761a commit 33b58a0

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

testdata/reflect.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,24 @@ type myErrorStringer struct{}
615615
func (myErrorStringer) Error() string { return "err" }
616616
func (myErrorStringer) String() string { return "str" }
617617

618+
// Interface with unexported method (from upstream set_test.go).
619+
type exprLike interface {
620+
Pos() int
621+
End() int
622+
exprNode()
623+
}
624+
625+
type notAnExpr struct{}
626+
627+
func (notAnExpr) Pos() int { return 0 }
628+
func (notAnExpr) End() int { return 0 }
629+
func (notAnExpr) exprNode() {}
630+
631+
// Named types for assignability tests (from upstream set_test.go).
632+
type IntPtr *int
633+
type IntPtr1 *int
634+
type Ch <-chan interface{}
635+
618636
func testImplements() {
619637
readerType := reflect.TypeOf((*Reader)(nil)).Elem()
620638
writerType := reflect.TypeOf((*Writer)(nil)).Elem()
@@ -710,6 +728,25 @@ func testImplements() {
710728
println("int → interface{}:", reflect.TypeOf(0).AssignableTo(emptyItf)) // true
711729
println("Reader → interface{}:", readerType.AssignableTo(emptyItf)) // true
712730

731+
// --- Upstream set_test.go: unexported method interfaces ---
732+
println("unexported method interface:")
733+
exprType := reflect.TypeOf((*exprLike)(nil)).Elem()
734+
println("*notAnExpr → exprLike:", reflect.TypeOf(new(notAnExpr)).Implements(exprType)) // true
735+
println("notAnExpr → exprLike:", reflect.TypeOf(notAnExpr{}).Implements(exprType)) // true
736+
println("*notAnExpr → exprLike (AssignableTo):", reflect.TypeOf(new(notAnExpr)).AssignableTo(exprType)) // true
737+
738+
// --- Upstream set_test.go: channel direction assignability ---
739+
println("channel direction:")
740+
println("chan int → <-chan int:", reflect.TypeOf(make(chan int)).AssignableTo(reflect.TypeOf(make(<-chan int)))) // true
741+
println("<-chan int → chan int:", reflect.TypeOf(make(<-chan int)).AssignableTo(reflect.TypeOf(make(chan int)))) // false
742+
743+
// --- Upstream set_test.go: named type assignability ---
744+
println("named types:")
745+
println("*int → IntPtr:", reflect.TypeOf(new(int)).AssignableTo(reflect.TypeOf(IntPtr(nil)))) // true
746+
println("IntPtr → *int:", reflect.TypeOf(IntPtr(nil)).AssignableTo(reflect.TypeOf(new(int)))) // true
747+
println("IntPtr → IntPtr1:", reflect.TypeOf(IntPtr(nil)).AssignableTo(reflect.TypeOf(IntPtr1(nil)))) // false
748+
println("Ch → <-chan interface{}:", reflect.TypeOf(Ch(nil)).AssignableTo(reflect.TypeOf(make(<-chan interface{})))) // true
749+
713750
// --- reflect.Value.Set with interface (issue #4277) ---
714751
println("value set interface:")
715752
type Node interface{ node() }

testdata/reflect.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,18 @@ ReadWriter → Reader: true
487487
Reader → ReadWriter: false
488488
int → interface{}: true
489489
Reader → interface{}: true
490+
unexported method interface:
491+
*notAnExpr → exprLike: true
492+
notAnExpr → exprLike: true
493+
*notAnExpr → exprLike (AssignableTo): true
494+
channel direction:
495+
chan int → <-chan int: true
496+
<-chan int → chan int: false
497+
named types:
498+
*int → IntPtr: true
499+
IntPtr → *int: true
500+
IntPtr → IntPtr1: false
501+
Ch → <-chan interface{}: true
490502
value set interface:
491503
Set[0] to BarNode: 10
492504
Set[1] still FooNode: 2

0 commit comments

Comments
 (0)