-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make quoted.Type fully contextual #10207
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
+4 −4 | pprint/src-3/TPrintImpl.scala | |
+0 −1 | pprint/src/pprint/PPrinter.scala |
+1 −1 | munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala |
+2 −2 | scalactic.dotty/src/main/scala/org/scalactic/source/TypeInfoMacro.scala |
+3 −3 | utest/src-3/utest/asserts/Asserts.scala | |
+7 −5 | utest/src-3/utest/asserts/Tracer.scala |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ import scala.annotation.compileTimeOnly | |
abstract class Type[T <: AnyKind] private[scala]: | ||
type Underlying = T | ||
|
||
def unseal(using qctx: QuoteContext): qctx.reflect.TypeTree | ||
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. From the tests, it seems this method is more convenient and shorter than the proposed alternative. Conceptually, it also helps reinforce the boundary between the safer quoted world and the unsafe reflect world. In addition, the method is also symmetric to 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. The idea is that the The most common use case is to inspect the type for which There are some tests that used to give a name to the Another classical mistake is to start with 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. I see in #10232 One ergonomics issue (might just be personal preference) is that I find dot-style API ( |
||
|
||
object Type: | ||
@compileTimeOnly("Reference to `scala.quoted.Type.apply` was not handled by ReifyQuotes") | ||
given apply[T <: AnyKind] as (QuoteContext ?=> Type[T]) = ??? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import scala.quoted._ | ||
|
||
|
||
inline def isFunctionType[T]: Boolean = ${ isFunctionTypeImpl(Type[T]) } | ||
inline def isFunctionType[T]: Boolean = ${ isFunctionTypeImpl[T] } | ||
|
||
def isFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
def isFunctionTypeImpl[T: Type](using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.reflect._ | ||
Expr(tp.unseal.tpe.isFunctionType) | ||
Expr(TypeRepr.of[T].isFunctionType) | ||
} | ||
|
||
|
||
inline def isContextFunctionType[T]: Boolean = ${ isContextFunctionTypeImpl(Type[T]) } | ||
inline def isContextFunctionType[T]: Boolean = ${ isContextFunctionTypeImpl[T] } | ||
|
||
def isContextFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
def isContextFunctionTypeImpl[T: Type](using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.reflect._ | ||
Expr(tp.unseal.tpe.isContextFunctionType) | ||
Expr(TypeRepr.of[T].isContextFunctionType) | ||
} | ||
|
||
|
||
inline def isErasedFunctionType[T]: Boolean = ${ isErasedFunctionTypeImpl(Type[T]) } | ||
inline def isErasedFunctionType[T]: Boolean = ${ isErasedFunctionTypeImpl[T] } | ||
|
||
def isErasedFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
def isErasedFunctionTypeImpl[T: Type](using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.reflect._ | ||
Expr(tp.unseal.tpe.isErasedFunctionType) | ||
Expr(TypeRepr.of[T].isErasedFunctionType) | ||
} | ||
|
||
inline def isDependentFunctionType[T]: Boolean = ${ isDependentFunctionTypeImpl(Type[T]) } | ||
inline def isDependentFunctionType[T]: Boolean = ${ isDependentFunctionTypeImpl[T] } | ||
|
||
def isDependentFunctionTypeImpl[T](tp: Type[T])(using qctx: QuoteContext) : Expr[Boolean] = { | ||
def isDependentFunctionTypeImpl[T: Type](using qctx: QuoteContext) : Expr[Boolean] = { | ||
import qctx.reflect._ | ||
Expr(tp.unseal.tpe.isDependentFunctionType) | ||
Expr(TypeRepr.of[T].isDependentFunctionType) | ||
} | ||
|
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.
Why is that cast needed?
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.
More precisely, why is it
Type[TypeTree]
and notType[T]
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.
Because it is the
scala.internal.quoted.Type
and notscala.quoted.Type
. That variant is parametrised with the tree type to make it easier to cast and extract internally.