From 2d9378c7f6dfbbe82d1bbd806093c2dfe57d7e17 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
-The static type (or just type) of a variable is the
+The static type (or just type) of a variable is the
type given in its declaration, the type provided in the
new
call or composite literal, or the type of
an element of a structured variable.
@@ -672,8 +672,8 @@ which is the concrete type of the value assigned to the variable at run time
which has no type).
The dynamic type may vary during execution but values stored in interface
variables are always assignable
-to the static type of the variable.
-
var x interface{} // x is nil and has static type interface{} @@ -4550,6 +4550,7 @@ In an expression switch, the cases contain expressions that are compared against the value of the switch expression. In a type switch, the cases contain types that are compared against the type of a specially annotated switch expression. +The switch expression is evaluated exactly once in a switch statement.+Expression switches
@@ -4576,6 +4577,27 @@ ExprCaseClause = ExprSwitchCase ":" StatementList . ExprSwitchCase = "case" ExpressionList | "default" .
+If the switch expression evaluates to an untyped constant, it is first
+converted to its default type;
+if it is an untyped boolean value, it is first converted to type bool
.
+The predeclared untyped value nil
cannot be used as a switch expression.
+
+If a case expression is untyped, it is first converted
+to the type of the switch expression.
+For each (possibly converted) case expression x
and the value t
+of the switch expression, x == t
must be a valid comparison.
+
+In other words, the switch expression is treated as if it were used to declare and
+initialize a temporary variable t
without explicit type; it is that
+value of t
against which each case expression x
is tested
+for equality.
+
In a case or default clause, the last non-empty statement may be a (possibly labeled) @@ -4588,7 +4610,7 @@ but the last clause of an expression switch.
-The expression may be preceded by a simple statement, which +The switch expression may be preceded by a simple statement, which executes before the expression is evaluated.
@@ -4611,6 +4633,13 @@ case x == 4: f3() } ++Implementation restriction: A compiler may disallow multiple case +expressions evaluating to the same constant. +For instance, the current compilers disallow duplicate integer, +floating point, or string constants in case expressions. +
+-- 2.50.0