Redesign: Propose Implicit Casting of Mutable- to Immutable Types
romshark opened this issue · 0 comments
Explicit casting will make this proposal break backward-compatibility with existing Go 1.x code because some parts of the standard library could to be rewritten to actually make use of the new immutability feature, which would cause existing Go 1.x code fail compiling in a newer compiler version with immutable type support.
The built-in append
function should, for example, be rewritten, to make use of the immutability feature, in the following way:
func append(slicе [] const Type, elems ...const Type) []Type
This is necessary to make append
guarantee not touching any of the inputs excepts the given slice (but not the Type
's inside the slice). But this would break all existing Go 1.x code, because it would then require explicit type casting:
v := []int {1, 2, 3}
// The "old" way of using append will stop working:
v = append(v, 4, 5) // Compile-time error
// The "new" way would be:
v = append(const(v), const(4), const(5)) // Compile-time error
Proposal Redesign
In order to avoid breaking backward-compatibility implicit casting must be proposed instead.