Skip to content

Implement ExplicitNullaryEtaExpansion #15

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

Merged
merged 1 commit into from
Apr 15, 2020

Conversation

dwijnand
Copy link
Collaborator

@dwijnand dwijnand commented Apr 3, 2020

No description provided.

@dwijnand

This comment has been minimized.

@dwijnand dwijnand force-pushed the nullary-eta-expansion branch from 2e72db5 to 49f324d Compare April 6, 2020 09:42
@dwijnand dwijnand changed the title Implement ExplicitNullaryEtaExpansion (ish..) [WIP] Implement ExplicitNullaryEtaExpansion (ish..) Apr 6, 2020
@dwijnand

This comment has been minimized.

@dwijnand dwijnand force-pushed the nullary-eta-expansion branch from 49f324d to 70eb877 Compare April 11, 2020 08:03
@dwijnand dwijnand changed the title [WIP] Implement ExplicitNullaryEtaExpansion (ish..) Implement ExplicitNullaryEtaExpansion Apr 11, 2020
@dwijnand
Copy link
Collaborator Author

All resolved - good to go!

@dwijnand dwijnand requested a review from lrytz April 11, 2020 08:04
override def fix(implicit doc: SemanticDocument) = {
doc.tree.collect { case eta: Term.Eta =>
eta.expr.symbol.info.map(_.signature).collect {
case MethodSignature(_, Nil, _) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

So for nullary methods that override a nilary one, there's no rewrite because the Scala compiler inserts the () parameter list. I guess that's fine, because f _ is allowed in this case.

Scala 2.13.x with -Xsource:3

scala> class C { override def toString = "" }
class C

scala> (new C).toString _
val res2: () => String = $Lambda$989/107279519@60ab895f

Dotty:

scala> class C { override def toString = "" }
// defined class C

scala> (new C).toString _
1 |(new C).toString _
  |^^^^^^^^^^^^^^^^^^
  |Only function types can be followed by _ but the current expression has type String

scala> class D { override def toString() = "" }
// defined class D

scala> (new D).toString _
val res4: () => String = Lambda$1255/1401633928@19b9f903

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but we have no override information in rewrites, so can't do anything about that 😞 (see #14 (comment))

@dwijnand dwijnand merged commit 171edbb into lightbend-labs:master Apr 15, 2020
@dwijnand dwijnand deleted the nullary-eta-expansion branch April 15, 2020 11:15
@dwijnand dwijnand restored the nullary-eta-expansion branch April 15, 2020 11:15
@dwijnand dwijnand deleted the nullary-eta-expansion branch April 15, 2020 11:15
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.

2 participants