Skip to content

Commit 2dd0a9e

Browse files
Merge pull request #8957 from dotty-staging/fix-#8879
Fix #8879: Add Reflection.Type.select
2 parents b0c010e + 93e0140 commit 2dd0a9e

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12151215
tpNoRefinement != self && defn.isNonRefinedFunction(tpNoRefinement)
12161216
}
12171217

1218+
def Type_select(self: Type)(sym: Symbol)(using ctx: Context): Type =
1219+
self.select(sym)
1220+
12181221
type ConstantType = Types.ConstantType
12191222

12201223
def isInstanceOfConstantType(using ctx: Context): IsInstanceOf[ConstantType] = new {

library/src/scala/tasty/Reflection.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,9 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
16781678
* @see `isFunctionType`
16791679
*/
16801680
def isDependentFunctionType(using ctx: Context): Boolean = internal.Type_isDependentFunctionType(self)
1681+
1682+
/** The type <this . sym>, reduced if possible */
1683+
def select(sym: Symbol)(using ctx: Context): Type = internal.Type_select(self)(sym)
16811684
}
16821685

16831686
given (using ctx: Context) as IsInstanceOf[Type] = internal.isInstanceOfType

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ trait CompilerInterface {
885885
*/
886886
def Type_isFunctionType(self: Type)(using ctx: Context): Boolean
887887

888-
889888
/** Is this type an context function type?
890889
*
891890
* @see `Type_isFunctionType`
@@ -904,6 +903,9 @@ trait CompilerInterface {
904903
*/
905904
def Type_isDependentFunctionType(self: Type)(using ctx: Context): Boolean
906905

906+
/** The type <this . sym>, reduced if possible */
907+
def Type_select(self: Type)(sym: Symbol)(using ctx: Context): Type
908+
907909
/** A singleton type representing a known constant value */
908910
type ConstantType <: Type
909911

tests/pos-macros/i8879/Macro_1.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
case class Foo[A](a: A)
2+
3+
object Test {
4+
5+
import scala.quoted._
6+
7+
def impl[T](t: T)(using qctx: QuoteContext, tt: Type[T]): Expr[Any] = {
8+
9+
import qctx.tasty._
10+
import util._
11+
12+
val foo = typeOf[Foo[String]]
13+
val symbol = foo.typeSymbol.field("a")
14+
val a = foo.select(symbol)
15+
assert(a <:< defn.StringType)
16+
17+
'{???}
18+
}
19+
20+
21+
inline def apply[T](inline t: T) = ${ Test.impl('t )}
22+
23+
}

tests/pos-macros/i8879/Test_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
object Run {
3+
def test(): Unit = {
4+
Test[Foo[String]](Foo("moo"))
5+
}
6+
}

0 commit comments

Comments
 (0)