1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:07:57 -07:00

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

Fixes #2700.

R=rsc
CC=golang-dev
https://golang.org/cl/5574046
This commit is contained in:
Luuk van Dijk 2012-01-24 13:53:00 +01:00
parent 0442087f93
commit 0e919ff2c9
2 changed files with 22 additions and 7 deletions

View File

@ -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",

View File

@ -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:
}
}