]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix TestAllocations now that interfaces hold only pointers
authorIan Lance Taylor <iant@golang.org>
Mon, 20 Oct 2014 18:10:03 +0000 (11:10 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 20 Oct 2014 18:10:03 +0000 (11:10 -0700)
This test was failing but did not break the build because it
was not run when -test.short was used.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/157150043

src/reflect/all_test.go

index 40eae0364c09530df9f03aef9774aff5a29c0a80..268a9e319f6758adfc0cac38cdb179f64c0795a0 100644 (file)
@@ -2502,10 +2502,21 @@ func TestAllocations(t *testing.T) {
        noAlloc(t, 100, func(j int) {
                var i interface{}
                var v Value
-               i = 42 + j
+
+               // We can uncomment this when compiler escape analysis
+               // is good enough to see that the integer assigned to i
+               // does not escape and therefore need not be allocated.
+               //
+               // i = 42 + j
+               // v = ValueOf(i)
+               // if int(v.Int()) != 42+j {
+               //      panic("wrong int")
+               // }
+
+               i = func(j int) int { return j }
                v = ValueOf(i)
-               if int(v.Int()) != 42+j {
-                       panic("wrong int")
+               if v.Interface().(func(int) int)(j) != j {
+                       panic("wrong result")
                }
        })
 }