Skip to content

Simplify import of qctx.tasty.rootContext #8438

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
//////////////

/** Context of the macro expansion */
given rootContext as Context = internal.rootContext // TODO: Use given // TODO: Should this be moved to QuoteContext?
def rootContext: Context = internal.rootContext // TODO: Should this be moved to QuoteContext?
given Context = rootContext // TODO: Should be an implicit converion from QuoteContext to Context
Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems not useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is to be able to access the rootContext by name when only importing import qctx.tasty._ , otherwise it is only visible with the given import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing changed for summoning it


extension ContextOps on (self: Context) {
/** Returns the owner of the context */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object SourceFiles {

def getThisFileImpl: Macro[String] = {
val qctx = tastyContext
import qctx.tasty.{_, given _}
import qctx.tasty._
Copy link
Contributor

Choose a reason for hiding this comment

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

We have many such cases in the test set, change them too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still need to adapt unseal to be able to change them all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #8441

rootContext.source.getFileName.toString
}

Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/tasty-getfile/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ object SourceFiles {
${getThisFileImpl}

private def getThisFileImpl(using qctx: QuoteContext) : Expr[String] = {
import qctx.tasty.{_, given _}
rootContext.source.getFileName.toString
import qctx.tasty._
summon[Context].source.getFileName.toString
}

}