Skip to content

Commit 7d196fc

Browse files
committed
go/ssa/interp: fix failing recover2.go test
The "unhashable" panic message had changed in go1.14. Fixes golang/go#34089 Change-Id: I6ba97d33fefee9e217b65904db2b07c2091d80be Reviewed-on: https://go-review.googlesource.com/c/tools/+/621676 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Tim King <[email protected]> Commit-Queue: Alan Donovan <[email protected]>
1 parent f861377 commit 7d196fc

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

go/ssa/interp/interp_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ func init() {
153153
}
154154

155155
func run(t *testing.T, input string, goroot string) {
156-
// The recover2 test case is broken on Go 1.14+. See golang/go#34089.
157-
// TODO(matloob): Fix this.
158-
if filepath.Base(input) == "recover2.go" {
159-
t.Skip("The recover2.go test is broken in go1.14+. See golang.org/issue/34089.")
160-
}
161-
162156
t.Logf("Input: %s\n", input)
163157

164158
start := time.Now()

go/ssa/interp/value.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (x array) hash(t types.Type) int {
141141
h := 0
142142
tElt := t.Underlying().(*types.Array).Elem()
143143
for _, xi := range x {
144-
h += hash(tElt, xi)
144+
h += hash(t, tElt, xi)
145145
}
146146
return h
147147
}
@@ -164,7 +164,7 @@ func (x structure) hash(t types.Type) int {
164164
h := 0
165165
for i, n := 0, tStruct.NumFields(); i < n; i++ {
166166
if f := tStruct.Field(i); !f.Anonymous() {
167-
h += hash(f.Type(), x[i])
167+
h += hash(t, f.Type(), x[i])
168168
}
169169
}
170170
return h
@@ -183,8 +183,8 @@ func (x iface) eq(t types.Type, _y interface{}) bool {
183183
return sameType(x.t, y.t) && (x.t == nil || equals(x.t, x.v, y.v))
184184
}
185185

186-
func (x iface) hash(_ types.Type) int {
187-
return hashType(x.t)*8581 + hash(x.t, x.v)
186+
func (x iface) hash(outer types.Type) int {
187+
return hashType(x.t)*8581 + hash(outer, x.t, x.v)
188188
}
189189

190190
func (x rtype) hash(_ types.Type) int {
@@ -256,7 +256,8 @@ func equals(t types.Type, x, y value) bool {
256256
}
257257

258258
// Returns an integer hash of x such that equals(x, y) => hash(x) == hash(y).
259-
func hash(t types.Type, x value) int {
259+
// The outer type is used only for the "unhashable" panic message.
260+
func hash(outer, t types.Type, x value) int {
260261
switch x := x.(type) {
261262
case bool:
262263
if x {
@@ -308,7 +309,7 @@ func hash(t types.Type, x value) int {
308309
case rtype:
309310
return x.hash(t)
310311
}
311-
panic(fmt.Sprintf("%T is unhashable", x))
312+
panic(fmt.Sprintf("unhashable type %v", outer))
312313
}
313314

314315
// reflect.Value struct values don't have a fixed shape, since the

0 commit comments

Comments
 (0)