]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: test that Call results are not addressable
authorIan Lance Taylor <iant@golang.org>
Tue, 12 Apr 2016 22:47:17 +0000 (15:47 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 12 Apr 2016 23:14:16 +0000 (23:14 +0000)
Gccgo was erroneously marking Call results as addressable, which led to
an obscure bug using text/template, as text/template calls CanAddr to
check whether to take the address of a value when looking up methods.
When a function returned a pointer, and CanAddr was true, the result was
a pointer to a pointer that had no methods.

Fixed in gccgo by https://golang.org/cl/21908.  Adding the test here so
that it doesn't regress.

Change-Id: I1d25b868e1b8e2348b21cbac6404a636376d1a4a
Reviewed-on: https://go-review.googlesource.com/21930
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/reflect/all_test.go

index 4a76ef86084705f3f098482d02975256084ddc83..e1b26d9c68a80cbbc30d22482d7796b2c09deb60 100644 (file)
@@ -1476,6 +1476,12 @@ func TestFunc(t *testing.T) {
        if i != 10 || j != 20 || k != 30 || l != (two{40, 50}) || m != 60 || n != 70 || o != 80 {
                t.Errorf("Call returned %d, %d, %d, %v, %d, %g, %d; want 10, 20, 30, [40, 50], 60, 70, 80", i, j, k, l, m, n, o)
        }
+
+       for i, v := range ret {
+               if v.CanAddr() {
+                       t.Errorf("result %d is addressable", i)
+               }
+       }
 }
 
 type emptyStruct struct{}