From: Robert Griesemer
@@ -2312,7 +2314,8 @@ ExpressionList = Expression { "," Expression } .
If the type is present, all constants take the type specified, and
-the expressions must be assignable to that type.
+the expressions must be assignable to that type,
+which must not be a type parameter.
If the type is omitted, the constants take the
individual types of the corresponding expressions.
If the expression values are untyped constants,
@@ -5197,7 +5200,6 @@ as for non-constant x.
Converting a constant to a type that is not a type parameter yields a typed constant. -Converting a constant to a type parameter yields a non-constant value of that type.
@@ -5215,6 +5217,29 @@ int(1.2) // illegal: 1.2 cannot be represented as an int string(65.0) // illegal: 65.0 is not an integer constant+
+Converting a constant to a type parameter yields a non-constant value of that type, +with the value represented as a value of the type argument that the type parameter +is instantiated with. +For example, given the function: +
+ +
+func f[P ~float32|~float64]() {
+ ⦠P(1.1) â¦
+}
+
+
+
+the conversion P(1.1) results in a non-constant value of type P
+and the value 1.1 is represented as a float32 or a float64
+depending on the type argument for f.
+Accordingly, if f is instantiated with a float32 type,
+the numeric value of the expression P(1.1) + 1.2 will be computed
+with the same precision as the corresponding non-constant float32
+addition.
+
A non-constant value x can be converted to type T
in any of these cases: