From 3d81d4adc9419e2fcba5888ab074d3f17eb5eb03 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 31 May 2016 13:32:34 -0700 Subject: [PATCH] spec: document that duplicate types are invalid in type switches Both compilers and also go/types don't permit duplicate types in type switches; i.e., this spec change is documenting a status quo that has existed for some time. Furthermore, duplicate nils are not accepted by gccgo or go/types; and more recently started causing a compiler error in gc. Permitting them is inconsistent with the existing status quo. Rather than making it an implementation restriction (as we have for expression switches), this is a hard requirement since it was enforced from the beginning (except for duplicate nils); it is also a well specified requirement that does not pose a significant burden for an implementation. Fixes #15896. Change-Id: If12db5bafa87598b323ea84418cb05421e657dd8 Reviewed-on: https://go-review.googlesource.com/23584 Reviewed-by: Rob Pike Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 13dae09420..731186e66b 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -4672,6 +4672,8 @@ Cases then match actual types T against the dynamic type of the expression x. As with type assertions, x must be of interface type, and each non-interface type T listed in a case must implement the type of x. +The types listed in the cases of a type switch must all be +different.

@@ -4696,6 +4698,7 @@ in the TypeSwitchGuard.
 The type in a case may be nil;
 that case is used when the expression in the TypeSwitchGuard
 is a nil interface value.
+There may be at most one nil case.
 

-- 2.50.0