-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Stub implementation of xml interpolator #5096
Conversation
facdf69
to
e07e72e
Compare
List(Typed(Repeated(values), _)))) if values.forall(isStringConstant) => | ||
values.collect { case Literal(Constant.String(value)) => value } | ||
case _ => | ||
??? |
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.
This should only happen if you write explicitly something like
val sc = new StringContext(...)
new XmlQuote(sc).xml(...)
you can emit an error in this case using new scala.quoted.QuotedError(...)
which will be translated into a compilation error.
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.
Thanks. I think we are still missing the ability to report an error at a custom position
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.
Yes we are. Should not be hard to add.
val parts = ctx.toTasty match { | ||
case Inlined(_, _, | ||
Apply( | ||
Select(Select(Select(Ident("_root_"), "scala", _), "StringContext", _), "apply", _), |
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.
In tasty.definition
you should have types or symbols for root and scala. You should be able to test this in the guard.
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.
Doesn't look simpler. It is more correct?
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.
Then this is fine. I expected it to look simpler
|
||
case class Xml(parts: String, arg: Any) | ||
|
||
class XmlQuote(ctx: StringContext) { |
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.
Shouldn't this class extend AnyVal
?
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 doesn't matter for performance. The code is elided by the macro. So the simpler, the better
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.
Even the allocation of the XmlQuote is elided?
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 my intuition (based on how Scala 2 macros work) was wrong. The receiver of the macro doesn't get elided. I opened #5110
e07e72e
to
92ab218
Compare
@nicolasstucki @biboudis I think this is good enough as a test and a proof of concept. Real development is happening here |
case class Xml(parts: String, args: List[Any]) | ||
|
||
// Ideally should be an implicit class but the implicit conversion | ||
// has to be a rewrite method |
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.
Good point, I think this is the best solution. Otherwise, we would need something like implicit rewrite class XmlQuote(...)
. Maybe with proper extension methods this will not be an issue.
We will still need to enable the test when #5119 is fixed. |
No description provided.