From 82a0188c88bd7bb0fbf31f10157b77beb2195594 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 20 Oct 2014 11:10:03 -0700 Subject: [PATCH] reflect: fix TestAllocations now that interfaces hold only pointers 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 | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 40eae0364c..268a9e319f 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -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") } }) } -- 2.50.0