Fix right associativity of extension methods #19203
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch removes the special treatment of extension methods while desugaring. Instead of swapping the arguments of the extension method at definition site, we let the usual desugaring take care of it.
This implies that the following makes sense now:
Note that the parameters are passed in order as in the signature, as they should. This used to break intuition in the previous implementation.
Futhermore, this fixes parameter scoping and dependencies, as it trivially respects the original signature. An example of this is in the following code example, where
T
is bounded bytuple.type
, which would have been out of scope in the previous implementation due to the swapping of parameters.The downside is that this is a breaking change as we change the semantics of the extension method definitions. We need to find a way to migrate from one to the other without breaking code. One option might be to have a different syntax for the new semantics, and deprecate the old one. One possibility would be to use
infix def
extensions to mark to mark these methods.One issue encountered in the library is with the
IArray.{++:, +:}
operations. Luckily, it seems that by rewriting them into the new semantics we get a binary and TASTy compatible signature.Fixes #19197
Needs SIP