Skip to content

Commit 39e5237

Browse files
committed
cmd/compile: fix another invalid switch case panic
Very similar fix to the one made in golang.org/cl/65655. This time it's for switches on interface values, as we look for duplicates in a different manner to keep types in mind. As before, add a small regression test. Updates #22001. Fixes #22063. Change-Id: I9a55d08999aeca262ad276b4649b51848a627b02 Reviewed-on: https://go-review.googlesource.com/66450 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 70bcd2c commit 39e5237

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/cmd/compile/internal/gc/swt.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,11 @@ func checkDupExprCases(exprname *Node, clauses []*Node) {
640640
if ct := consttype(n); ct < 0 || ct == CTBOOL {
641641
continue
642642
}
643+
// If the value has no type, we have
644+
// already printed an error about it.
645+
if n.Type == nil {
646+
continue
647+
}
643648
tv := typeVal{
644649
typ: n.Type.LongString(),
645650
val: n.Val().Interface(),

test/fixedbugs/issue22063.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// errorcheck
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 22063: panic on interface switch case with invalid name
8+
9+
package p
10+
11+
const X = Wrong(0) // ERROR "undefined: Wrong"
12+
13+
func _() {
14+
switch interface{}(nil) {
15+
case X:
16+
}
17+
}

0 commit comments

Comments
 (0)