Skip to content

Move Unliftable extractors in Unlifted #8517

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
23 changes: 20 additions & 3 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,32 @@ class Expr[+T] private[scala] {
* Returns `None` if the expression does not contain a value or contains side effects.
* Otherwise returns the `Some` of the value.
*/
@deprecated("Use Expr.unlift", "0.23")
final def getValue[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): Option[U] = unlift(this)

/** Return the value of this expression.
/** Return the unlifted value of this expression.
*
* Returns `None` if the expression does not contain a value or contains side effects.
* Otherwise returns the `Some` of the value.
*/
final def unlift[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): Option[U] =
unlift(this)

/** Return the unlifted value of this expression.
*
* Emits an error error and throws if the expression does not contain a value or contains side effects.
* Otherwise returns the value.
*/
@deprecated("Use Expr.unlifted", "0.23")
final def value[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U = unlifted

/** Return the unlifted value of this expression.
*
* Emits an error error and throws if the expression does not contain a value or contains side effects.
* Otherwise returns the value.
*/
final def value[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U =
unlift(this).getOrElse(qctx.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be recovered using $unlift", this))
final def unlifted[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U =
unlift(this).getOrElse(qctx.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be unlifted using $unlift", this))

/** Pattern matches `this` against `that`. Effectively performing a deep equality check.
* It does the equivalent of
Expand Down
Loading