You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it is pretty clear that the second one will almost always be because of a wrong keystroke or an oversight. But scalac manages to parse it, and completely ignores the parenthesis to the right of c, resulting in something that the author probably didn't intend (or he would have written it that way).
Some convoluted example to show this can lead to unexpected results:
scala>objecta { defb(x: Any) = hasD }; objecthasD { defd(x: Any) = x }; objecte; valc= hasD
defined objecta
defined objecthasD
defined objecte
c: hasD.type= hasD$@4bb2ee58
scala> a b(c).d(e)
res1: hasD.type= hasD$@4bb2ee58
scala> a.b(c).d(e)
res2:Any= e$@756c6202
@som-snytt said:
Counter-example is "hello" +("world").length, but wasn't there talk about an annotation to specify if infix is recommended or allowed?
Maybe an Abide rule could be endowed with suitable heuristics.
@adriaanm said:
There's certainly scope for a linter/style checker to flag infix method calls as suspicious if the method name is not in a whitelist of infix operator names, but infix syntax is not something we can remove outright. True, a + (c).d(e) is more likely to be as intended than a b (c).d(e), but we cannot distinguish them during parsing.
Scalac manages to parse both of the following expressions:
I think it is pretty clear that the second one will almost always be because of a wrong keystroke or an oversight. But scalac manages to parse it, and completely ignores the parenthesis to the right of
c
, resulting in something that the author probably didn't intend (or he would have written it that way).Some convoluted example to show this can lead to unexpected results:
Example it can lead to very confusing compiler errors: http://stackoverflow.com/questions/41600172/scala-multiple-type-parameter-that-are-defined-later
The text was updated successfully, but these errors were encountered: