Skip to content

Commit e4d5f8c

Browse files
committed
fixes scala#8514, TypeApi#baseType exposed into Tasty
1 parent bb23fea commit e4d5f8c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

library/src/scala/tasty/Reflection.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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(using ctx: Context)(cls: Symbol): 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)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)