Skip to content

Fix #9529: Desugar ExtMethods in expression position #9553

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
Aug 14, 2020

Conversation

nicolasstucki
Copy link
Contributor

Desugar the extension method into a block with a Unit expression.
Also set a missing position for the ExtMethods tree.

@nicolasstucki nicolasstucki marked this pull request as ready for review August 13, 2020 14:35
@nicolasstucki nicolasstucki requested a review from smarter August 13, 2020 14:35
@@ -1715,6 +1715,8 @@ object desugar {
case PatDef(mods, pats, tpt, rhs) =>
val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
flatTree(pats1 map (makePatDef(tree, mods, _, rhs)))
case ext: ExtMethods =>
Block(List(ext), Literal(Constant(())).withSpan(ext.span))
Copy link
Member

Choose a reason for hiding this comment

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

If this can only happen in case of error, maybe the parser should be changed to not try to parse extension methods in such positions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would we special case extensions? Isn't it better to handle them the same as defs? I would expect that the following would befave similarly

def f1: Unit = { def g = 0 }
def f2: Unit = { extension (x: Int) def g = 0 }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, same error should be emitted for

def f1: Int = { def g = 0 } // error: Found: Unit   Required: Int
def f2: Int = { extension (x: Int) def g = 0 } // error: Found: Unit   Required: Int

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok then is it possible to have a pos test for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, ill add the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added these tests

Desugar the extension method into a block with a Unit expression.
Also set a missing position for the ExtMethods tree.
@nicolasstucki nicolasstucki merged commit 1b64c60 into scala:master Aug 14, 2020
@nicolasstucki nicolasstucki deleted the fix-#9529 branch August 14, 2020 14:41
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