Skip to content

Remove unnecessary indirection #8500

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
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
6 changes: 4 additions & 2 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import scala.quoted.show.SyntaxHighlight
class Expr[+T] private[scala] {

/** Show a source code like representation of this expression without syntax highlight */
def show(using qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)
def show(using qctx: QuoteContext): String =
this.unseal.showWith(SyntaxHighlight.plain)

/** Show a source code like representation of this expression */
def show(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
def show(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String =
this.unseal.showWith(syntaxHighlight)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: a complex import for just one line of code does not look nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be able to remove with #8502. I will rebase and check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. I removed the imports.


/** Return the value of this expression.
*
Expand Down
12 changes: 0 additions & 12 deletions library/src/scala/quoted/QuoteContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ class QuoteContext(val tasty: scala.tasty.Reflection) { self =>
val tasty: self.tasty.type
}

/** Show the fully elaborated source code representation of an expression */
def show(expr: Expr[_], syntaxHighlight: SyntaxHighlight): String = {
import tasty.{_, given _}
expr.unseal(using this).showWith(syntaxHighlight)
}

/** Show the fully elaborated source code representation of a type */
def show(tpe: Type[_], syntaxHighlight: SyntaxHighlight): String = {
import tasty.{_, given _}
tpe.unseal(using this).showWith(syntaxHighlight)
}

/** Report an error at the position of the macro expansion */
def error(msg: => String): Unit = {
import tasty.{_, given _}
Expand Down
6 changes: 4 additions & 2 deletions library/src/scala/quoted/Type.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class Type[T <: AnyKind] private[scala] {
type `$splice` = T

/** Show a source code like representation of this type without syntax highlight */
def show(using qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)
def show(using qctx: QuoteContext): String =
this.unseal.showWith(SyntaxHighlight.plain)

/** Show a source code like representation of this type */
def show(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
def show(syntaxHighlight: SyntaxHighlight)(using qctx: QuoteContext): String =
this.unseal.showWith(syntaxHighlight)

/** View this expression `quoted.Type[T]` as a `TypeTree` */
def unseal(using qctx: QuoteContext): qctx.tasty.TypeTree =
Expand Down