proposal: Go 2: spec: allow unary + on string #27657
Labels
FrozenDueToAge
LanguageChange
Suggested changes to the Go language
Proposal
v2
An incompatible library change
Milestone
Problem
Especially with generics coming up where operators become important, the following contracts are different, even though they may look like they are the same:
Note that the following contracts are currently equivalent:
If someone wants an obvious "I want to allow numeric addition and not concatenation", they can much more explicitly say it like so:
Solution
This is what the following is said by the spec:
I propose it be changed to something similar to the following:
Impact
This would have an extremely small impact on programming in Go, but in contract-writing this could hide away one of those "weird cases". It prevents a library writer from seeing this case and using
+a
to mean "numeric addition only" in a contract, which may not be immediately obvious to a reader.This also means that in the future of Go, if more types (ie matrices) are added, if binary operators defined on them, the unary operators will also be defined on them. Even though this is unlikely, I think it's a good thing to add.
This is also a very small change, and should be Go 1 compatible. This needs to have a decision either with or before Go 2 though, because of contract equivalence.
The text was updated successfully, but these errors were encountered: