1
0
mirror of https://github.com/golang/go synced 2024-11-22 03:04:41 -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); 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",

View File

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