File tree Expand file tree Collapse file tree 6 files changed +47
-0
lines changed
compiler/src/dotty/tools/dotc/tastyreflect Expand file tree Collapse file tree 6 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -1205,6 +1205,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12051205 def Type_baseClasses (self : Type )(using Context ): List [Symbol ] =
12061206 self.baseClasses
12071207
1208+ def Type_baseType (self : Type )(cls : Symbol )(using Context ): Type =
1209+ self.baseType(cls)
1210+
12081211 def Type_derivesFrom (self : Type )(cls : Symbol )(using Context ): Boolean =
12091212 self.derivesFrom(cls)
12101213
Original file line number Diff line number Diff line change @@ -1812,6 +1812,17 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
18121812 /** The base classes of this type with the class itself as first element. */
18131813 def baseClasses (using ctx : Context ): List [Symbol ] = internal.Type_baseClasses (self)
18141814
1815+
1816+ /** The least type instance of given class which is a super-type
1817+ * of this type. Example:
1818+ * {{{
1819+ * class D[T]
1820+ * class C extends p.D[Int]
1821+ * ThisType(C).baseType(D) = p.D[Int]
1822+ * }}}
1823+ */
1824+ def baseType (cls : Symbol )(using ctx : Context ): Type = internal.Type_baseType (self)(cls)
1825+
18151826 /** Is this type an instance of a non-bottom subclass of the given class `cls`? */
18161827 def derivesFrom (cls : Symbol )(using ctx : Context ): Boolean =
18171828 internal.Type_derivesFrom (self)(cls)
Original file line number Diff line number Diff line change @@ -876,6 +876,16 @@ trait CompilerInterface {
876876 /** The base classes of this type with the class itself as first element. */
877877 def Type_baseClasses (self : Type )(using ctx : Context ): List [Symbol ]
878878
879+ /** The least type instance of given class which is a super-type
880+ * of this type. Example:
881+ * {{{
882+ * class D[T]
883+ * class C extends p.D[Int]
884+ * ThisType(C).baseType(D) = p.D[Int]
885+ * }}}
886+ */
887+ def Type_baseType (self : Type )(cls : Symbol )(using ctx : Context ): Type
888+
879889 /** Is this type an instance of a non-bottom subclass of the given class `cls`? */
880890 def Type_derivesFrom (self : Type )(cls : Symbol )(using ctx : Context ): Boolean
881891
Original file line number Diff line number Diff line change 1+ B
2+ A[[T >: scala.Nothing <: scala.Any] => P[T], scala.Predef.String]
3+ java.lang.Object
4+ scala.Any
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+
3+ class A [+ X [_], - Y ]
4+ class P [T ]
5+ class B extends A [P , String ]
6+
7+ inline def test (): Unit = $ { testExpr }
8+
9+ def testExpr (using QuoteContext ): Expr [Unit ] = {
10+ import qctx .tasty ._
11+
12+ val t = ' [B ].unseal.tpe
13+ val baseTypes = t.baseClasses.map(b => t.baseType(b))
14+
15+ ' {
16+ println($ {Expr (baseTypes.map(_.show).mkString(" \n " ))})
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ @ main def Test = test()
You can’t perform that action at this time.
0 commit comments