Right associative extension method allow apparent forward reference between parameters #16815
Labels
area:extension-methods
area:reporting
Error reporting including formatting, implicit suggestions, etc
area:typer
better-errors
Issues concerned with improving confusing/unhelpful diagnostic messages
itype:bug
Milestone
Compiler version
Scala 3.2.2
Minimized code
https://scastie.scala-lang.org/4LgQkgomTNijNcj1BjhGPw
More examples here (tests all confusing situations):
https://scastie.scala-lang.org/B4eX394PQbazeycIPqWiXQ
Expectation
Should not compile
Why it happens
Right associative extension methods go through a confusing swap*, for example the method above becomes:
Which is indeed a valid method (if you ignore the curried type clauses), even though the original is invalid
*At the time of writing, it is described incorrectly in the reference, and a fixed version for it is here
Why it matters
While it is fine to give surprising tricks to language experts, in this case, this can have very confusing repercussions for normal users:
How to fix it
My proposal is the following:
In case the swapped groups of clauses (
leftParams trailingUsing
andrightTyParam rightParam
) have any reference to something defined in the other group, throw an errorThe error should clearly explain why it is not allowed, and maybe solutions for the problem
The text was updated successfully, but these errors were encountered: