From 9871726c72af7009aa73be33edfa06a8d9e5965e Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 18 Aug 2021 09:38:19 -0700 Subject: [PATCH] reflect: add test for invalid conversion Conversion between slices with different element types is not allowed. Previously (1.8 <= goversion <= 1.16), this conversion was allowed if the base types were from different packages and had identical names. Update #47785 Change-Id: I359de5b6fe3ff35bdbf9ab5a13902a0f820cac66 Reviewed-on: https://go-review.googlesource.com/c/go/+/343329 Trust: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- src/reflect/all_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 5e5e4c1e604..df79f058075 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -7296,4 +7296,11 @@ func TestConvertibleTo(t *testing.T) { if t1.ConvertibleTo(t2) { t.Fatalf("(%s).ConvertibleTo(%s) = true, want false", t1, t2) } + + t3 := ValueOf([]example1.MyStruct{}).Type() + t4 := ValueOf([]example2.MyStruct{}).Type() + + if t3.ConvertibleTo(t4) { + t.Fatalf("(%s).ConvertibleTo(%s) = true, want false", t3, t4) + } }