-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rename Liftable
to ToExpr
and Unliftable
to FromExpr
#10618
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+1 −1 | dotty/core/src/main/scala/org/scalatest/Assertions.scala | |
+6 −6 | dotty/core/src/main/scala/org/scalatest/CompileMacro.scala |
+3 −3 | core/shared/src/main/scala-3/scodec/bits/bits/Interpolators.scala |
+1 −1 | src/main/scala/dotty/xml/interpolator/internal/Macro.scala |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,26 @@ object Expr { | |
Block(statements.map(Term.of), Term.of(expr)).asExpr.asInstanceOf[Expr[T]] | ||
} | ||
|
||
/** Lift a value into an expression containing the construction of that value */ | ||
def apply[T](x: T)(using lift: Liftable[T])(using Quotes): Expr[T] = | ||
lift.toExpr(x) | ||
/** Creates an expression that will construct the value `x` */ | ||
def apply[T](x: T)(using ToExpr[T])(using Quotes): Expr[T] = | ||
scala.Predef.summon[ToExpr[T]].apply(x) | ||
|
||
/** Lifts this sequence of expressions into an expression of a sequence | ||
/** Get `Some` of a copy of the value if the expression contains a literal constant or constructor of `T`. | ||
* Otherwise returns `None`. | ||
* | ||
* Usage: | ||
* ``` | ||
* case '{ ... ${expr @ Expr(value)}: T ...} => | ||
* // expr: Expr[T] | ||
* // value: T | ||
* ``` | ||
* | ||
* To directly get the value of an expression `expr: Expr[T]` consider using `expr.value`/`expr.valueOrError` insead. | ||
*/ | ||
def unapply[T](x: Expr[T])(using FromExpr[T])(using Quotes): Option[T] = | ||
scala.Predef.summon[FromExpr[T]].unapply(x) | ||
|
||
/** Creates an expression that will construct a copy of this sequence | ||
* | ||
* Transforms a sequence of expression | ||
* `Seq(e1, e2, ...)` where `ei: Expr[T]` | ||
|
@@ -43,7 +58,7 @@ object Expr { | |
def ofSeq[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]] = | ||
Varargs(xs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That won't work, the name of the method is not to distinguish the arguments but the target type. Let's keep this for a follow-up PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can only have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part of the API clearly needs a deeper analysis. I will try it in a separate PR and we can keep this one only to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It seems to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid confusions we need to have Would you understand if you relate the Some(2) match
case Just(n) =>
// or
Just(2) match
case Some(n) => I would find it extremely confusing and would probably assume they are different concepts. Even though logically they are the dual of each other. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a difference here: for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be true for trees but here we are on the |
||
|
||
/** Lifts this list of expressions into an expression of a list | ||
/** Creates an expression that will construct a copy of this list | ||
* | ||
* Transforms a list of expression | ||
* `List(e1, e2, ...)` where `ei: Expr[T]` | ||
|
@@ -53,7 +68,7 @@ object Expr { | |
def ofList[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[List[T]] = | ||
if (xs.isEmpty) Expr(Nil) else '{ List(${Varargs(xs)}: _*) } | ||
|
||
/** Lifts this sequence of expressions into an expression of a tuple | ||
/** Creates an expression that will construct a copy of this tuple | ||
* | ||
* Transforms a sequence of expression | ||
* `Seq(e1, e2, ...)` where `ei: Expr[Any]` | ||
|
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.
If we want to keep this general extractor, a more informative name like
Value
might be better.Uh oh!
There was an error while loading. Please reload this page.
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 thought about that one. The issue is that it would either fragment concepts into
Expr.apply
/Value.unapply
or we would need to duplicate some logic betweenExpr
andValue
which might lead to confusion.