Skip to content
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

Update and correct macro cross tutorial #3031

Closed
wants to merge 1 commit into from

Conversation

som-snytt
Copy link
Contributor

Fixes scala/scala3#20591

Besides the use of jpath, the scala 2 macro impl must be public. I tried to verify the steps as presented, but did not quite have the patience; probably the sophisticated user will fill in any gaps.

It's hard not to turn it into an sbt tutorial.

It's nicer just to say + test.

@@ -191,9 +192,9 @@ object Macros:
private def locationImpl(using quotes: Quotes): Expr[Location] =
import quotes.reflect.Position
val pos = Position.ofMacroExpansion
val file = Expr(pos.sourceFile.jpath.toString)
val path = Expr(pos.sourceFile.path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

They preferred getJPath.getOrElse on the related PR. But I think source must have a path, but may not have a file. A source must have a path because I need to be able to report errors at a location, even if the location is virtual. It's not a Scala thing but an API thing.

@som-snytt som-snytt closed this Aug 10, 2024
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.

Issue with macros and in-memory (virtual) source files
1 participant