Commit 0e919ff2 authored by Luuk van Dijk's avatar Luuk van Dijk

gc: static implements check on typeswitches only applies to concrete case types.

Fixes #2700.

R=rsc
CC=golang-dev
https://golang.org/cl/5574046
parent 0442087f
...@@ -889,7 +889,7 @@ typecheckswitch(Node *n) ...@@ -889,7 +889,7 @@ typecheckswitch(Node *n)
yyerror("%lN is not a type", ll->n); yyerror("%lN is not a type", ll->n);
// reset to original type // reset to original type
ll->n = n->ntest->right; ll->n = n->ntest->right;
} else if(!implements(ll->n->type, t, &missing, &have, &ptr)) { } else if(ll->n->type->etype != TINTER && !implements(ll->n->type, t, &missing, &have, &ptr)) {
if(have && !missing->broke && !have->broke) if(have && !missing->broke && !have->broke)
yyerror("impossible type switch case: %lN cannot have dynamic type %T" yyerror("impossible type switch case: %lN cannot have dynamic type %T"
" (wrong type for %S method)\n\thave %S%hT\n\twant %S%hT", " (wrong type for %S method)\n\thave %S%hT\n\twant %S%hT",
......
...@@ -6,15 +6,30 @@ ...@@ -6,15 +6,30 @@
package main package main
import (
"io"
)
type I interface { type I interface {
M() M()
} }
func main(){ func main(){
var x I var x I
switch x.(type) { switch x.(type) {
case string: // ERROR "impossible" case string: // ERROR "impossible"
println("FAIL") println("FAIL")
} }
// Issue 2700: if the case type is an interface, nothing is impossible
var r io.Reader
_, _ = r.(io.Writer)
switch r.(type) {
case io.Writer:
}
} }
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