Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
def Type_baseClasses(self: Type)(using Context): List[Symbol] =
self.baseClasses

def Type_baseType(self: Type)(cls: Symbol)(using Context): Type =
self.baseType(cls)

def Type_derivesFrom(self: Type)(cls: Symbol)(using Context): Boolean =
self.derivesFrom(cls)

Expand Down
11 changes: 11 additions & 0 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,17 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
/** The base classes of this type with the class itself as first element. */
def baseClasses(using ctx: Context): List[Symbol] = internal.Type_baseClasses(self)


/** The least type instance of given class which is a super-type
* of this type. Example:
* {{{
* class D[T]
* class C extends p.D[Int]
* ThisType(C).baseType(D) = p.D[Int]
* }}}
*/
def baseType(cls: Symbol)(using ctx: Context): Type = internal.Type_baseType(self)(cls)

/** Is this type an instance of a non-bottom subclass of the given class `cls`? */
def derivesFrom(cls: Symbol)(using ctx: Context): Boolean =
internal.Type_derivesFrom(self)(cls)
Expand Down
10 changes: 10 additions & 0 deletions library/src/scala/tasty/reflect/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,16 @@ trait CompilerInterface {
/** The base classes of this type with the class itself as first element. */
def Type_baseClasses(self: Type)(using ctx: Context): List[Symbol]

/** The least type instance of given class which is a super-type
* of this type. Example:
* {{{
* class D[T]
* class C extends p.D[Int]
* ThisType(C).baseType(D) = p.D[Int]
* }}}
*/
def Type_baseType(self: Type)(cls: Symbol)(using ctx: Context): Type

/** Is this type an instance of a non-bottom subclass of the given class `cls`? */
def Type_derivesFrom(self: Type)(cls: Symbol)(using ctx: Context): Boolean

Expand Down
4 changes: 4 additions & 0 deletions tests/run-macros/i8514b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
B
A[[T >: scala.Nothing <: scala.Any] => P[T], scala.Predef.String]
java.lang.Object
scala.Any
18 changes: 18 additions & 0 deletions tests/run-macros/i8514b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.quoted._

class A[+X[_], -Y]
class P[T]
class B extends A[P, String]

inline def test(): Unit = ${ testExpr }

def testExpr(using QuoteContext): Expr[Unit] = {
import qctx.tasty._

val t = '[B].unseal.tpe
val baseTypes = t.baseClasses.map(b => t.baseType(b))

'{
println(${Expr(baseTypes.map(_.show).mkString("\n"))})
}
}
1 change: 1 addition & 0 deletions tests/run-macros/i8514b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@main def Test = test()