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

Implement ExplicitNonNullaryApply #14

Merged
merged 7 commits into from Apr 21, 2020

Conversation

dwijnand
Copy link
Collaborator

@dwijnand dwijnand commented Apr 2, 2020

Heavily inspired by Olaf's scalacenter/scalafix#204.

@dwijnand

This comment has been minimized.

Copy link

@ohze ohze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwijnand

This comment has been minimized.

Two problems:

* ScalaMeta's SymbolInformation seems to record asInstanceOf as nilary
  instead of nullary, so the rewrite erroneously rewrites the
  _definitions_ propNullAs and methNullAs, into invalid code... :(  I
  could move the definitions into another file, but I just decided to
  drop it, also because...

* Infix invocation of nilary methods seems to be no longer valid in
  2.13, for example:

    [error] /d/scala-rewrites/output/src/main/scala/fix/scala213/ExplicitNonNullaryApply.scala:30:42: no arguments allowed for nullary method methNullAs: ()A
    [error]   def def_this_methNullAs_m_in    = this methNullAs         ()
    [error]                                          ^

Also, "nullAs" is the closest and only method I could think of that is
nilary (actually I normally define "nullAs" as nullary) and takes no
term arguments but makes legitimate use of the type parameter.  So maybe
the whole edge-case is a pointless variation.
What we'd like is to leave any call to a method that was defined in Java
(or any "universal" method, like ##, eq, isInstanceOf) to be exempt.

It appears Scalameta/Semanticdb/Scalafix doesn't capture that
information, and thus basically all of them get parens... :(

Apparently in Metals they use the presentation compiler to recover all
the missing info and I know in ScalaClean they have their own nsc
Traverser, I'm guessing for the same reason.
@dwijnand
Copy link
Collaborator Author

Ouch, that looks like a lot of code... 😕

Fortunately not necessary: I was able to use ScalafixGlobal to implement a "isJavaDefined" so any method defined in Java is invoked as it is (with or without (), no rewriting).

Need to review the diff as a whole now before declaring it ready.

@dwijnand dwijnand changed the title Implement ExplicitNonNullaryApply, using Olaf's draft Implement ExplicitNonNullaryApply Apr 21, 2020
@dwijnand dwijnand marked this pull request as ready for review April 21, 2020 19:35
@dwijnand dwijnand merged commit 1a7e3c8 into lightbend-labs:master Apr 21, 2020
@dwijnand dwijnand deleted the no-auto-apply branch April 21, 2020 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants