diff options
author | Luuk van Dijk <lvd@golang.org> | 2011-11-09 10:58:53 +0100 |
---|---|---|
committer | Luuk van Dijk <lvd@golang.org> | 2011-11-09 10:58:53 +0100 |
commit | 0e6dcb96cc1ba42346852c335f356b20e97eccc7 (patch) | |
tree | 9d35c67eefa6be532b8983389a8faad486b6ed63 /test/switch3.go | |
parent | eba49edee3172517f6d67f8b27455c21ed0a48be (diff) | |
download | go-0e6dcb96cc1ba42346852c335f356b20e97eccc7.tar.gz |
gc: Better typechecks and errors in switches.
Allow any type in switch on interface value.
Statically check typeswitch early.
Fixes issue 2423.
Fixes issue 2424.
R=rsc, dsymonds
CC=golang-dev
http://codereview.appspot.com/5339045
Diffstat (limited to 'test/switch3.go')
-rw-r--r-- | test/switch3.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/switch3.go b/test/switch3.go new file mode 100644 index 000000000..95ff6ec3c --- /dev/null +++ b/test/switch3.go @@ -0,0 +1,38 @@ +// errchk $G -e $D/$F.go + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + + +type I interface { + M() +} + +func bad() { + var i I + var s string + + switch i { + case s: // ERROR "mismatched types string and I" + } + + switch s { + case i: // ERROR "mismatched types I and string" + } +} + +func good() { + var i interface{} + var s string + + switch i { + case s: + } + + switch s { + case i: + } +} |