Skip to content
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

Merged
merged 1 commit into from
Feb 20, 2023

Conversation

kitbellew
Copy link
Collaborator

Specifically, implicitParamListModifierForce=after should not apply when implicit is explicit rather than applies once to the entire group. Helps with #3466.

Specifically, implicitParamListModifierForce=after should not apply when
`implicit` is explicit rather than applies once to the entire group.
@kitbellew kitbellew requested a review from tgodzik February 20, 2023 15:04
@@ -4277,17 +4277,14 @@ object a:
)(b: B,
bs: B*
)(implicit
implicit
c: C) {}
implicit c: C) {}
Copy link
Contributor

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 🤔

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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
)

Copy link
Contributor

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.

Copy link
Collaborator Author

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...

Copy link
Contributor

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

Copy link
Collaborator Author

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).

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants