Open Sporarum opened 1 year ago
Ping @sjrd @smarter as we discussed this briefly in person
For the reference part, it might be useful to tackle the two following issues at the same time: https://github.com/lampepfl/dotty/issues/17593 https://github.com/lampepfl/dotty/issues/17429
We discussed with @mbovel, and while this is way too big to be a Spree issue in itself, subparts seem suitable. If smaller issues are opened, they will be mentioned below
Compiler version
Tested on 3.3.1-RC1 with
-source:future
, but unlikely to have changedCurrent State
The reference page describing infix calls mentions two places where
infix
is allowed (without saying these are necessarily the only two):and
However, I found
infix
is also allowed in the following (doubles as example for later):Notably,
infix
is not allowed onimport
andexport
toplevel
can never be called as infix, the intent was probably aninfix
extension methodI would have expected to be able to call for example
v
in an infix matter, this is not allowed, all of the following throw "expression expected but end of statement found" (also the case if we remove theinfix
s):If we add right-hand sides, we have the following:
But neither
O
norC
are methods, and more importantly, they are bothinline
!And finally if we remove
infix
from the definitions, we get this (with shortened warnings):As we can see, neither
v
norg
emit a warning ! (This might be becauseFunction1.apply
was compiled with Scala 2)Adding
infix
toO.apply
leads to no warnings, whether or notO
is itselfinfix
!The reference is also silent on types taking any other amount than 2 parameters, here is what I found:
The following is also undocumented:
Summary
infix
is valid, and has undocumented positive effect ontrait
s andclasses
taking exactly 2 type parameters, andtypes
taking 0 parameters.infix
is valid, but has no effect onval
,object
,given
, as well as in the following particular cases:type
not taking 0 or 2 parametersclass
ortrait
not taking 2 parameterdef
def
taking 0 parameters (behaves the same asv
above)Expectation
infix
should only be allowed in front of constructs it can modify. Currently:def
,type
,trait
,class
In other cases, it should return a similar error asinfix export
, or a better oneIn cases where
infix
has no effect (currently: "particular cases" above), a warning should be emittedEvery
ninfixN
should throw a "not infix" warningThe following should display a special warning:
infix
auxiliary constructors should be either documented, emit a warning, or throw an error