-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1503: anonymous application of FunctionX #1508
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,7 +533,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
def typedBlock(tree: untpd.Block, pt: Type)(implicit ctx: Context) = track("typedBlock") { | ||
val exprCtx = index(tree.stats) | ||
val stats1 = typedStats(tree.stats, ctx.owner) | ||
val expr1 = typedExpr(tree.expr, pt)(exprCtx) | ||
|
||
// A block might appear in function position after desugaring (see | ||
// i1503.scala), so adaptation may insert a `.apply` at the end of expr1. | ||
// When this happens we simply remove the select to make expr1 a valid | ||
// block expression. The `.apply` will be added back around the block when | ||
// the block itself is adapted later. | ||
val expr1 = typedExpr(tree.expr, pt)(exprCtx) match { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what if the .apply was added explicitly by the user? Then it should not be removed. It seems we need another solution. |
||
case Select(x, nme.apply) => x | ||
case x => x | ||
} | ||
ensureNoLocalRefs( | ||
assignType(cpy.Block(tree)(stats1, expr1), stats1, expr1), pt, localSyms(stats1)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
working |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
object Test { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put the run test in the same commit where the problem is fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, was planning on cleaning up this PR this morning - thanks for having a look already :) |
||
def main(args: Array[String]): Unit = { | ||
(new Function0[Unit] { | ||
def apply() = println("working") | ||
})() | ||
} | ||
} |
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.
style changes should be in separate commits from functional changes
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.
Done 👍