Skip to content

Commit 0d34aa4

Browse files
committed
Fix type of modue objects
1 parent 77e7a3b commit 0d34aa4

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
426426
def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = {
427427
def printSeparated(list: List[TypeTree]): Unit = list match {
428428
case Nil =>
429-
case x :: Nil => printTypeTree(x)
429+
case x :: Nil => printTypeTreeTop(x)
430430
case x :: xs =>
431-
printTypeTree(x)
431+
printTypeTreeTop(x)
432432
this += sep
433433
printSeparated(xs)
434434
}
@@ -609,6 +609,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
609609
printTypeTree(tpt)
610610
}
611611

612+
def printTypeTreeTop(tree: TypeTree): Buffer = tree match {
613+
case TypeTree.Synthetic() => printTypeTop(tree.tpe)
614+
case TypeTree.TypeIdent(name) => printTypeTop(tree.tpe)
615+
case _ => printTypeTree(tree)
616+
}
617+
612618
def printTypeTree(tree: TypeTree): Buffer = tree match {
613619
case TypeTree.Synthetic() =>
614620
printType(tree.tpe)
@@ -673,13 +679,25 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
673679
case tpe@Type() => printType(tpe)
674680
}
675681

682+
def printTypeTop(tree: Type): Buffer = tree match {
683+
case Type.TypeRef(name, prefix) =>
684+
prefix match {
685+
case NoPrefix() | Type.ThisType(Types.EmptyPackage()) =>
686+
case prefix@Type() => printType(prefix) += "."
687+
}
688+
if (name.endsWith("$")) this += name.stripSuffix("$") += ".type"
689+
else this += name
690+
case _ => printType(tree)
691+
}
692+
676693
def printType(tpe: Type): Buffer = tpe match {
677694
case Type.ConstantType(const) =>
678695
printConstant(const)
679696

680697
case Type.SymRef(sym, prefix) =>
681698
prefix match {
682699
case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) =>
700+
case Type.ThisType(Type.SymRef(ClassDef(_, _, _, _, _), _)) =>
683701
case prefix@Type.SymRef(ClassDef(_, _, _, _, _), _) =>
684702
printType(prefix)
685703
this += "#"
@@ -706,9 +724,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
706724
case Type.TypeRef(name, prefix) =>
707725
prefix match {
708726
case NoPrefix() | Type.ThisType(Types.EmptyPackage()) =>
709-
case prefix@Type() =>
710-
printType(prefix)
711-
this += "."
727+
case prefix@Type() => printType(prefix) += "."
712728
}
713729
this += name.stripSuffix("$")
714730

tests/pos/i2104.decompiled

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
class Cons[H, T]() extends java.lang.Object
33
object Cons {
44
def apply[H, T](h: H, t: T): Cons[H, T] = scala.Predef.???
5-
def unapply[H, T](t: Cons[H, T]): scala.Option[<empty>.Pair[H, T]] = scala.Predef.???
5+
def unapply[H, T](t: Cons[H, T]): scala.Option[Pair[H, T]] = scala.Predef.???
66
}/** Decompiled from out/posTestFromTasty/pos/i2104/Pair.class */
77
case class Pair[A, B](_1: A, _2: B) {
88
def copy[A >: scala.Nothing <: scala.Any, B >: scala.Nothing <: scala.Any](_1: A, _2: B): Pair[A, B] = new Pair[A, B](_1, _2)
9-
def copy$default$1[A >: scala.Nothing <: scala.Any, B >: scala.Nothing <: scala.Any]: Pair.A = (Pair._1: Pair._1)
10-
def copy$default$2[A >: scala.Nothing <: scala.Any, B >: scala.Nothing <: scala.Any]: Pair.B = (Pair._2: Pair._2)
9+
def copy$default$1[A >: scala.Nothing <: scala.Any, B >: scala.Nothing <: scala.Any]: A = (_1: _1)
10+
def copy$default$2[A >: scala.Nothing <: scala.Any, B >: scala.Nothing <: scala.Any]: B = (_2: _2)
1111
override def hashCode(): scala.Int = {
1212
var acc: scala.Int = 2479866
13-
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(Pair._1))
14-
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(Pair._2))
13+
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(_1))
14+
acc = scala.runtime.Statics.mix(acc, scala.runtime.Statics.anyHash(_2))
1515
scala.runtime.Statics.finalizeHash(acc, 2)
1616
}
1717
override def equals(x$0: scala.Any): scala.Boolean = this.eq(x$0.asInstanceOf[java.lang.Object]).||(x$0 match {
18-
case x$0: Pair[Pair.A, Pair.B] =>
18+
case x$0: Pair[A, B] =>
1919
this._1.==(x$0._1).&&(this._2.==(x$0._2))
2020
case _ =>
2121
false
2222
})
2323
override def toString(): java.lang.String = scala.runtime.ScalaRunTime._toString(this)
24-
override def canEqual(that: scala.Any): scala.Boolean = that.isInstanceOf[Pair[Pair.A, Pair.B]]
24+
override def canEqual(that: scala.Any): scala.Boolean = that.isInstanceOf[Pair[A, B]]
2525
override def productArity: scala.Int = 2
2626
override def productPrefix: java.lang.String = "Pair"
2727
override def productElement(n: scala.Int): scala.Any = n match {
@@ -39,12 +39,12 @@ object Pair extends scala.AnyRef {
3939
}/** Decompiled from out/posTestFromTasty/pos/i2104/Test.class */
4040
object Test {
4141
def main(args: scala.Array[scala.Predef.String]): scala.Unit = {
42-
<empty>.Cons.apply[scala.Option[scala.Int], scala.None](scala.Option.apply[scala.Int](1), scala.None) match {
43-
case <empty>.Cons.unapply[scala.Option[scala.Int], scala.None](, scala.None) =>
42+
Cons.apply[scala.Option[scala.Int], scala.None.type](scala.Option.apply[scala.Int](1), scala.None) match {
43+
case Cons(_: scala.Some[scala.Int], scala.None) =>
4444
{
4545
(i: scala.Int)
4646
dotty.DottyPredef.assert(i.==(1))
4747
}
4848
}
4949
}
50-
}
50+
}

0 commit comments

Comments
 (0)