-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FormatOps vertical multiline: explicit implicits #3478
Conversation
Specifically, implicitParamListModifierForce=after should not apply when `implicit` is explicit rather than applies once to the entire group.
@@ -4277,17 +4277,14 @@ object a: | |||
)(b: B, | |||
bs: B* | |||
)(implicit | |||
implicit | |||
c: C) {} | |||
implicit c: C) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, how does it parse? Two implicits in a row doesn't parse for me 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, then we should change our scalameta parser :) or the grammar:
under https://dotty.epfl.ch/docs/internals/syntax.html#type-and-value-parameters
ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
...
ClsParam ::= ...
[{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
and under https://dotty.epfl.ch/docs/internals/syntax.html#bindings-and-imports
Modifier ::= LocalModifier
...
LocalModifier ::= ...
| ‘implicit’
so nothing really prevents multiple implicits. I don't know if {...}
means multiple different ones, but even in that case the first parameter is definitely covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the grammar then. Both the compiler and scalameta fail to parse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, if scalameta did fail to parse it, then scalafmt wouldn't be able to format it. perhaps a different dialect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in any case, this specific change doesn't really touch the multiple implicits logic, it's just some of the tests which are affected. unless, of course, the compiler doesn't allow explicit implicits all of a sudden, like:
...(
implicit a: A,
implicit b: B
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ach wait, that's my bad. It is possible for classes and not for defs, which I didn't realize. But it fails for both classes and defs when trying to compiler, so this seems like an issue in scalameta parser only.
But yeah, it's not strictly related to this PR I was just confused how this even parsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we open an issue in the parser and describe how it works? does it allow explicit implicits, does it require unique modifiers per parameter, does it only check consecutive ones? are there modifiers which aren't allowed at all?
ideally, they'd revise the grammar...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is an omission really and we can open an issue in the parser, but most other modifiers should be handled properly
just implicit/using are a weird case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tgodzik could you please check this:
class A(implicit implicit val a: String):
// foo
in my Intellij IDE it works (and without val
doesn't).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an error from the compiler: Repeated modifier implicit
Specifically, implicitParamListModifierForce=after should not apply when
implicit
is explicit rather than applies once to the entire group. Helps with #3466.