-
Couldn't load subscription status.
- Fork 1.1k
Fix regression #23969: Add ensureApplied to the quotes reflect API #24160
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
|
|
||
| import scala.quoted._ | ||
|
|
||
| object TestMethods: | ||
| def a1 = () | ||
| def a2() = () | ||
| def a3[T] = () | ||
| def a4[T]() = () | ||
|
|
||
| transparent inline def runMacro() = ${runMacroImpl} | ||
| def runMacroImpl(using Quotes): Expr[Any] = | ||
| import quotes.reflect._ | ||
|
|
||
| // ensureApplied test | ||
| Select.unique('{TestMethods}.asTerm, "a1").ensureApplied match | ||
| case Select(_, _) => | ||
| case _ => assert(false) | ||
| Select.unique('{TestMethods}.asTerm, "a2").ensureApplied match | ||
| case Apply(_, _) => | ||
| case _ => assert(false) | ||
| Select.unique('{TestMethods}.asTerm, "a3").ensureApplied match | ||
| case Select(_, _) => | ||
| case other => assert(false) | ||
| Select.unique('{TestMethods}.asTerm, "a4").ensureApplied 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. Mmmh, this is a legitimate question, but if we have a 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. This will result in: -- Error: tests/pos-macros/i23969/Main.scala:1:19 ------------------------------
1 |@main def Test() = runMacro()
| ^^^^^^^^^^
| method a4 in object TestMethods does not take parameterserror, thrown from tpd.Apply. Even if we were to change that, we would have to deal with the TreeChecker run right after the macro expansion. In general, I believe we have to return fully typed trees and I am not aware of any additional type inference done to inlined code after inlining it (so it will be done for quoted code before the macro is expanded, or for non-macro inline method contents, but not changed after inlining, even for non-macro transparent inline methods, more info here: #8739). Also apologies for weird response times! And thank you for looking at this @hamzaremmal |
||
| case Select(_, _) => | ||
| case other => assert(false) | ||
|
|
||
| TypeApply(Select.unique('{TestMethods}.asTerm, "a3"), List(TypeTree.of[Nothing])).ensureApplied match | ||
| case TypeApply(_, _) => | ||
| case other => assert(false) | ||
| TypeApply(Select.unique('{TestMethods}.asTerm, "a4"), List(TypeTree.of[Nothing])).ensureApplied match | ||
| case Apply(_, _) => | ||
| case other => assert(false) | ||
|
|
||
| // regression test | ||
| val Inlined(_, _, generated) = '{BigDecimal(0).toString()}.asTerm : @unchecked | ||
| val Inlined(_, _, bigDecimal) = '{BigDecimal(0)}.asTerm : @unchecked | ||
| val custom = Select.unique(bigDecimal, "toString").ensureApplied | ||
| // ensure both have the same shape | ||
| assert(custom.toString == generated.toString) | ||
| custom.asExpr | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @main def Test() = runMacro() |
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.
I'm curious about what will happen if we do this?
At least, we should include them in the test.