From: Robert Griesemer Date: Wed, 28 Apr 2021 01:05:20 +0000 (-0700) Subject: spec: clarify conditions for switch expression type X-Git-Tag: go1.17beta1~385 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=764f53eb6ccc55ad52ddfeed47485de76f4453bb;p=gostls13.git spec: clarify conditions for switch expression type 1. The existing prose implied that a switch expression type must be comparable because it is tested for equality against all case expressions. But for an empty switch (no case expressions), it was not clear if the switch expression needed to be comparable. Require it to match the behavior of compiler and type checkers. 2. While making this change, remove redundant language explaining what happens with untyped boolean switch expression values: the default type of an untyped boolean value is bool, this is already covered by the first part of the relevant sentence. Fixes #43200. Change-Id: Id8e0f29cfa8722b57cd2b7b58cba85b58c5f842b Reviewed-on: https://go-review.googlesource.com/c/go/+/314411 Trust: Robert Griesemer Reviewed-by: Matthew Dempsky Reviewed-by: Rob Pike --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 95bf7d30f8..e59b3554f2 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -4953,9 +4953,9 @@ ExprSwitchCase = "case" ExpressionList | "default" .

If the switch expression evaluates to an untyped constant, it is first implicitly -converted to its default type; -if it is an untyped boolean value, it is first implicitly converted to type bool. +converted to its default type. The predeclared untyped value nil cannot be used as a switch expression. +The switch expression type must be comparable.