Commit 63a6f305 authored by Russ Cox's avatar Russ Cox

cmd/compile: diagnose invalid switch interface{} case earlier

Fixes #11737.

Change-Id: Id231b502ac5a44035dc3a02515b43bf665cb1e87
Reviewed-on: https://go-review.googlesource.com/17816Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 91c8e5f8
......@@ -139,6 +139,8 @@ func typecheckswitch(n *Node) {
}
case nilonly != "" && !isnil(ll.N):
Yyerror("invalid case %v in switch (can only compare %s %v to nil)", ll.N, nilonly, n.Left)
case Isinter(t) && !Isinter(ll.N.Type) && algtype1(ll.N.Type, nil) == ANOEQ:
Yyerror("invalid case %v in switch (incomparable type)", Nconv(ll.N, obj.FmtLong))
}
// type switch
......
// errorcheck
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 11737 - invalid == not being caught until generated switch code was compiled
package p
func f()
func s(x interface{}) {
switch x {
case f: // ERROR "invalid case f \(type func\(\)\) in switch \(incomparable type\)"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment