diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index c2bb1173aced..3491375726f7 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -1215,6 +1215,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend tpNoRefinement != self && defn.isNonRefinedFunction(tpNoRefinement) } + def Type_select(self: Type)(sym: Symbol)(using ctx: Context): Type = + self.select(sym) + type ConstantType = Types.ConstantType def isInstanceOfConstantType(using ctx: Context): IsInstanceOf[ConstantType] = new { diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index d3f6e63719b7..f981cb1db3ba 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -1678,6 +1678,9 @@ class Reflection(private[scala] val internal: CompilerInterface) { self => * @see `isFunctionType` */ def isDependentFunctionType(using ctx: Context): Boolean = internal.Type_isDependentFunctionType(self) + + /** The type , reduced if possible */ + def select(sym: Symbol)(using ctx: Context): Type = internal.Type_select(self)(sym) } given (using ctx: Context) as IsInstanceOf[Type] = internal.isInstanceOfType diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index 55ac971e4ffb..4648c91511aa 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -885,7 +885,6 @@ trait CompilerInterface { */ def Type_isFunctionType(self: Type)(using ctx: Context): Boolean - /** Is this type an context function type? * * @see `Type_isFunctionType` @@ -904,6 +903,9 @@ trait CompilerInterface { */ def Type_isDependentFunctionType(self: Type)(using ctx: Context): Boolean + /** The type , reduced if possible */ + def Type_select(self: Type)(sym: Symbol)(using ctx: Context): Type + /** A singleton type representing a known constant value */ type ConstantType <: Type diff --git a/tests/pos-macros/i8879/Macro_1.scala b/tests/pos-macros/i8879/Macro_1.scala new file mode 100644 index 000000000000..fda2363167b0 --- /dev/null +++ b/tests/pos-macros/i8879/Macro_1.scala @@ -0,0 +1,23 @@ +case class Foo[A](a: A) + +object Test { + + import scala.quoted._ + + def impl[T](t: T)(using qctx: QuoteContext, tt: Type[T]): Expr[Any] = { + + import qctx.tasty._ + import util._ + + val foo = typeOf[Foo[String]] + val symbol = foo.typeSymbol.field("a") + val a = foo.select(symbol) + assert(a <:< defn.StringType) + + '{???} + } + + + inline def apply[T](inline t: T) = ${ Test.impl('t )} + +} diff --git a/tests/pos-macros/i8879/Test_2.scala b/tests/pos-macros/i8879/Test_2.scala new file mode 100644 index 000000000000..1398b274b0d6 --- /dev/null +++ b/tests/pos-macros/i8879/Test_2.scala @@ -0,0 +1,6 @@ + +object Run { + def test(): Unit = { + Test[Foo[String]](Foo("moo")) + } +}