]> Cypherpunks.ru repositories - gostls13.git/commitdiff
reflect: add test for invalid conversion
authorKeith Randall <khr@golang.org>
Wed, 18 Aug 2021 16:38:19 +0000 (09:38 -0700)
committerKeith Randall <khr@golang.org>
Thu, 19 Aug 2021 15:09:47 +0000 (15:09 +0000)
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 <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/reflect/all_test.go

index 5e5e4c1e6040893688f9c19d18b6863483553ae2..df79f058075f4b58e19549ae24d9c039b39771f4 100644 (file)
@@ -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)
+       }
 }