]> Cypherpunks repositories - gostls13.git/commitdiff
gc: static implements check on typeswitches only applies to concrete case types.
authorLuuk van Dijk <lvd@golang.org>
Tue, 24 Jan 2012 12:53:00 +0000 (13:53 +0100)
committerLuuk van Dijk <lvd@golang.org>
Tue, 24 Jan 2012 12:53:00 +0000 (13:53 +0100)
Fixes #2700.

R=rsc
CC=golang-dev
https://golang.org/cl/5574046

src/cmd/gc/swt.c
test/typeswitch3.go

index 6c0a9ac832f44f11a3ae81365e82f82feec9b30e..f1a95587fd679b045978f2d627e6a6d4671bfe72 100644 (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",
index 99d08a20f777d2a863304060d0d4f5f170720e1f..078980146f8b4aedf3eaaca339ff8735025acfc9 100644 (file)
@@ -6,15 +6,30 @@
 
 package main
 
+import (
+       "io"
+)
 
 type I interface {
-       M()
+       M()
 }
 
 func main(){
-       var x I
-       switch x.(type) {
-       case string:    // ERROR "impossible"
-               println("FAIL")
-       }
+       var x I
+       switch x.(type) {
+       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:
+       }
 }
+
+