Skip to content

Commit 5317da0

Browse files
committed
wip
1 parent 963719e commit 5317da0

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11141114

11151115
def Type_typeSymbol(self: Type) given Context: Symbol = self.typeSymbol
11161116

1117+
def Type_termSymbol(self: Type) given Context: Symbol = self.termSymbol
1118+
11171119
def Type_isSingleton(self: Type) given Context: Boolean = self.isSingleton
11181120

11191121
def Type_memberType(self: Type)(member: Symbol) given Context: Type =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,8 @@ trait CompilerInterface {
882882

883883
def Type_typeSymbol(self: Type) given (ctx: Context): Symbol
884884

885+
def Type_termSymbol(self: Type) given (ctx: Context): Symbol
886+
885887
def Type_isSingleton(self: Type) given (ctx: Context): Boolean
886888

887889
def Type_memberType(self: Type)(member: Symbol) given (ctx: Context): Type

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ trait Printers
308308
def visitType(x: TypeOrBounds): Buffer = x match {
309309
case Type.ConstantType(value) =>
310310
this += "Type.ConstantType(" += value += ")"
311-
case Type.TermRef(sym, qual) =>
312-
this += "Type.TermRef(" += sym += ", " += qual += ")"
311+
case Type.TermRef(qual, name) =>
312+
this += "Type.TermRef(" += qual+= ", " += name += ")"
313313
case Type.TypeRef(sym, qual) =>
314314
this += "Type.TypeRef(" += sym += ", " += qual += ")"
315315
case Type.NamedTermRef(name, qual) =>
@@ -1519,8 +1519,9 @@ trait Printers
15191519
case Type.ConstantType(const) =>
15201520
printConstant(const)
15211521

1522-
case Type.TypeRef(sym, prefix) =>
1523-
prefix match {
1522+
case Type.IsTypeRef(tpe) =>
1523+
val sym = tpe.typeSymbol
1524+
tpe.qualifier match {
15241525
case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
15251526
case NoPrefix() =>
15261527
if (sym.owner.flags.is(Flags.Package)) {
@@ -1529,7 +1530,7 @@ trait Printers
15291530
if (packagePath != "")
15301531
this += packagePath += "."
15311532
}
1532-
case IsType(prefix @ Type.TermRef(IsClassDefSymbol(_), _)) =>
1533+
case Type.IsTermRef(prefix) if prefix.termSymbol.isClass =>
15331534
printType(prefix)
15341535
this += "#"
15351536
case IsType(prefix @ Type.TypeRef(IsClassDefSymbol(_), _)) =>

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ trait SymbolOps extends Core {
8585

8686
def isType given (ctx: Context): Boolean = internal.matchTypeSymbol(self).isDefined
8787
def isTerm given (ctx: Context): Boolean = internal.matchTermSymbol(self).isDefined
88+
def isClass given (ctx: Context): Boolean = internal.matchClassDefSymbol(self).isDefined
8889
}
8990

9091
// PackageSymbol

library/src/scala/tasty/reflect/TypeOrBoundsOps.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait TypeOrBoundsOps extends Core {
2020

2121
def classSymbol given (ctx: Context): Option[ClassDefSymbol] = internal.Type_classSymbol(self)
2222
def typeSymbol given (ctx: Context): Symbol = internal.Type_typeSymbol(self)
23+
def termSymbol given (ctx: Context): Symbol = internal.Type_termSymbol(self)
2324
def isSingleton given (ctx: Context): Boolean = internal.Type_isSingleton(self)
2425
def memberType(member: Symbol) given (ctx: Context): Type = internal.Type_memberType(self)(member)
2526

@@ -84,8 +85,8 @@ trait TypeOrBoundsOps extends Core {
8485
}
8586

8687
object TermRef {
87-
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] =
88-
internal.matchTermRef_unapply(typeOrBounds)
88+
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(TypeOrBounds /* Type | NoPrefix */, String)] =
89+
internal.matchTermRef_unapply(typeOrBounds).map(x => (x.qu, x.name))
8990
}
9091

9192
object IsTypeRef {
@@ -299,6 +300,7 @@ trait TypeOrBoundsOps extends Core {
299300

300301
implicit class Type_TermRefAPI(self: TermRef) {
301302
def qualifier given (ctx: Context): TypeOrBounds /* Type | NoPrefix */ = internal.TermRef_qualifier(self)
303+
def name given (ctx: Context): String = internal.TermRef_name(self)
302304
}
303305

304306
implicit class Type_TypeRefAPI(self: TypeRef) {

0 commit comments

Comments
 (0)