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)
yyerror("%lN is not a type", ll->n);
// reset to original type
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)
yyerror("impossible type switch case: %lN cannot have dynamic type %T"
" (wrong type for %S method)\n\thave %S%hT\n\twant %S%hT",
......
......@@ -6,6 +6,9 @@
package main
import (
"io"
)
type I interface {
M()
......@@ -17,4 +20,16 @@ func main(){
case string: // ERROR "impossible"
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