-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Inlined non-eta-expanded trees message #11537
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
Conversation
-- Error: tests/pos-macros/i11483/Test_2.scala:25:11 -------------------------------------------------------------------
25 | Api.println(Api.doSomething())
| ^^^^^^^^^^^
| Cannot automaticaly eta-expand calls in macros: x.Api.println
| This location contains code that was inlined from Test_2.scala:25
inlined at Test_2.scala:24: |
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.
Otherwise, LGTM
@@ -223,6 +223,9 @@ object EtaExpansion extends LiftImpure { | |||
*/ | |||
def etaExpand(tree: Tree, mt: MethodType, xarity: Int)(using Context): untpd.Tree = { | |||
import untpd._ | |||
if ctx.phase == Phases.inliningPhase then | |||
report.error(em"Cannot automaticaly eta-expand calls in macros: $tree", tree.srcPos) | |||
return EmptyTree |
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.
Can we do the check from the place where etaExpand
is called?
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.
Actually, we can catch it as soon as it is created by the macro and give the stack trace to the user.
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.
Now it will fail under ycheck
with
24 | X.process[Future,Unit]{ // error
| ^
|Exception occurred while executing macro expansion.
|java.lang.AssertionError: assertion failed: Reference to a method must be eta-expanded before it is used as an expression: (
| {
| def $anonfun(x: concurrent.Future[String]): String =
| {
| x.await[concurrent.Future, String](x)(x.FutureAsyncMonad)
| }
| closure($anonfun:Conversion[concurrent.Future[String], String])
| }
|:Conversion[concurrent.Future[String], String]).apply
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$yCheckValidExpr(QuotesImpl.scala:2884)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Apply$.yCheckArgs$$anonfun$1(QuotesImpl.scala:603)
| at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
| at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
| at scala.collection.immutable.List.foreach(List.scala:333)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Apply$.yCheckArgs(QuotesImpl.scala:603)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Apply$.apply(QuotesImpl.scala:595)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Apply$.apply(QuotesImpl.scala:594)
| at x.X$.processTree(Macro_1.scala:50)
| at x.X$.processTree(Macro_1.scala:45)
| at x.X$.processTree(Macro_1.scala:42)
| at x.X$.processTree(Macro_1.scala:39)
| at x.X$.processImpl(Macro_1.scala:32)
This lets the user know that he created the wrong tree at Macro_1.scala:50
03b1cd9
to
9e5f77f
Compare
9e5f77f
to
04dba31
Compare
private def yCheckValidExpr(term: Term): term.type = | ||
if yCheck then | ||
assert(!term.tpe.widenDealias.isInstanceOf[dotc.core.Types.MethodicType], | ||
"Reference to a method must be eta-expanded before it is used as an expression: " + term.show) |
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.
For later: maybe provide a reflection API to perform eta-expansion?
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.
It seems such well-formedness checks are very useful in macros development.
Is it possible to centralize the check for the expanded tree? I guess for debugging, the current approach is more helpful, as it shows the stacktrace.
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.
For later: maybe provide a reflection API to perform eta-expansion?
We already have term.etaExpand
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.
Is it possible to centralize the check for the expanded tree?
Centralize how? Like in normal yCheck
?
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.
Centralize how? Like in normal
yCheck
?
Yes, something like a TreeMap
or ReTyper
. But as I mentioned above, this might not be a good idea, as it cannot show the stacktrace how an ill-formed tree is created.
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.
That did not work in this case because the crash happened before we finished the transformation in the Inlining
phase.
Closes #11483