Skip to content

Commit

Permalink
Merge pull request scala#8957 from dotty-staging/fix-#8879
Browse files Browse the repository at this point in the history
Fix scala#8879: Add Reflection.Type.select
  • Loading branch information
nicolasstucki authored May 12, 2020
2 parents b0c010e + 93e0140 commit 2dd0a9e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 <this . sym>, 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
Expand Down
4 changes: 3 additions & 1 deletion library/src/scala/tasty/reflect/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -904,6 +903,9 @@ trait CompilerInterface {
*/
def Type_isDependentFunctionType(self: Type)(using ctx: Context): Boolean

/** The type <this . sym>, 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

Expand Down
23 changes: 23 additions & 0 deletions tests/pos-macros/i8879/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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 )}

}
6 changes: 6 additions & 0 deletions tests/pos-macros/i8879/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

object Run {
def test(): Unit = {
Test[Foo[String]](Foo("moo"))
}
}

0 comments on commit 2dd0a9e

Please sign in to comment.