From 533dfd62919ecb69a39973cea32d06a1cb166687 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
-String literals represent constant values of type string
.
+String literals represent ideal string values. Ideal strings don't
+have a named type but they are compatible with type string
+(§Type identity and compatibility).
There are two forms: raw string literals and interpreted string
literals.
byte
, which is an alias for uint8
.
Conversions
-are required when different numeric types are mixed in an expression
+are required when incompatible numeric types are mixed in an expression
or assignment. For instance, int32
and int
are not the same type even though they may have the same size on a
particular architecture.
@@ -530,7 +533,7 @@ and false
.
-The string
type represents the set of textual string values.
+The string
type represents the set of string values.
Strings behave like arrays of bytes but are immutable: once created,
it is impossible to change the contents of a string.
@@ -1037,63 +1040,59 @@ received, closed(c)
returns true.
-Types may be different, structurally equal (or just equal), -or identical. -Go is type safe: different types cannot be mixed -in binary operations and values cannot be assigned to variables of different -types. Values can be assigned to variables of equal type. -
+Two types may be identical, compatible, or incompatible. +Two identical types are always compatible, but two compatible types may not be identical. +Go is type safe: a value of one type cannot be assigned to a variable of an +incompatible type, and two values of incompatible types cannot be mixed in +binary operations. + +-Two type names denote equal types if the types in the corresponding declarations -are equal (§Declarations and Scope). -Two type literals specify equal types if they have the same -literal structure and corresponding components have equal types. -In detail: +Two named types are identical if their type names originate in the same +type declaration (§Declarations and Scope). A named and an unnamed type +are never identical. Two unnamed types are identical if the corresponding +type literals have the same literal structure and corresponding components have +identical types. In detail:
-Type identity is more stringent than type equality. -It requires for type names -that they originate in the same type declaration, while for equality it requires -only that they originate in equal type declarations. -Also, the names of parameters and results must match for function types. -In all other respects, the definition of type identity is the -same as for type equality listed above but with ``identical'' -substitued for ``equal''. -
--By definition, identical types are also equal types. -Two types are different if they are not equal. +Type compatibility is less stringent than type identity: a named and an unnamed +type are compatible if the respective type literals are compatible. +In all other respects, the definition of type compatibility is the +same as for type identity listed above but with ``compatible'' +substituted for ``identical''.
@@ -1112,50 +1111,50 @@ type (
-these types are equal: +these types are identical:
T0 and T0 -T0 and T1 -T0 and []string -T4 and T5 -T3 and struct { a int; c int } +[]int and []int +struct { a, b *T5 } and struct { a, b *T5 } +func (x int, y float) *[]string and func (int, float) (result *[]string)
-T2
and T3
are not equal because
-they have different field names.
+T0
and T1
are neither identical nor compatible
+because they are named types with distinct declarations.
-These types are identical: +These types are compatible:
T0 and T0 -[]int and []int -struct { a, b *T5 } and struct { a, b *T5 } +T0 and []string +T3 and struct { a int; c int } +T4 and func (x int, y float) *[]string
-T0
and T1
are equal but not
-identical because they have distinct declarations.
+T2
and struct { a, c int }
are incompatible because
+they have different field names.
Values of any type may always be assigned to variables -of equal static type. Some types and values have conditions under which they may -be assigned to different types: +of compatible static type. Some types and values have conditions under which they may +be assigned to otherwise incompatible types:
nil
can be assigned to any
pointer, function, slice, map, channel, or interface variable.
-Values of any type may be compared to other values of equal static
+Values of any type may be compared to other values of compatible static
type. Values of numeric and string type may be compared using the
full range of comparison operators as described in §Comparison operators;
booleans may be compared only for equality or inequality.
@@ -1215,7 +1214,7 @@ Channel and map values are equal if they were created by the same call to
(§Making slices, maps, and channels).
a
of type M
or *M
where M
is a map type (§Map types):
x
's type must be equal to the key type of M
+ x
's type must be compatible with the key type of M
and the map must contain an entry with key x
(but see special forms below)
a[x]
is the map value with key x
and the type of a[x]
is the value type of M
@@ -2201,7 +2200,7 @@ The type of x
must be an interface type.
More precisely, if T
is not an interface type, x.(T)
asserts
that the dynamic type of x
is identical to the type T
-(§Type equality and identity).
+(§Type identity and compatibility).
If T
is an interface type, x.(T)
asserts that the dynamic type
of T
implements the interface T
(§Interface types).
TODO: gri wants an error if x is already of type T.
@@ -2343,7 +2342,7 @@ unary_op = "+" | "-" | "!" | "^" | "*" | "&" | "<-" .
-The operand types in binary operations must be equal, with the following exceptions: +The operand types in binary operations must be compatible, with the following exceptions:
@@ -3774,28 +3773,33 @@ The following conversion rules apply:
uint32(int8(0xFF))
is 0xFFFFFFFF
.
The conversion always yields a valid value; there is no signal for overflow.
@@ -3804,7 +3808,7 @@ string(0x65e5) // "\u65e5"
nil
, the result is the empty string.
@@ -3812,7 +3816,7 @@ string([]int{0x65e5, 0x672c, 0x8a9e}) // "\u65e5\u672c\u8a9e"
nil
,
the result is the empty string.
@@ -4254,7 +4258,7 @@ alignment of the (type of the) variable in bytes. For a variable
uintptr(unsafe.Pointer(&x)) % uintptr(unsafe.Alignof(x)) == 0- +
Calls to Alignof
, Offsetof
, and
Sizeof
are constant expressions of type int
.
--
2.48.1