Skip to content

Commit

Permalink
Avoid in ConstantTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Feb 24, 2023
1 parent ba481c6 commit 92118c4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5736,6 +5736,12 @@ object Types {
case tp @ SuperType(thistp, supertp) =>
derivedSuperType(tp, this(thistp), this(supertp))

case tp @ ConstantType(const @ Constant(_: Type)) =>
val classType = const.tpe
val classType1 = this(classType)
if classType eq classType1 then tp
else classType1

case tp: LazyRef =>
LazyRef { refCtx =>
given Context = refCtx
Expand Down
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ object Formatting {
given Show[TypeComparer.ApproxState] with
def show(x: TypeComparer.ApproxState) = TypeComparer.ApproxState.Repr.show(x)

given Show[ast.TreeInfo.PurityLevel] with
def show(x: ast.TreeInfo.PurityLevel) = x match
case ast.TreeInfo.Path => "PurityLevel.Path"
case ast.TreeInfo.Pure => "PurityLevel.Pure"
case ast.TreeInfo.Idempotent => "PurityLevel.Idempotent"
case ast.TreeInfo.Impure => "PurityLevel.Impure"
case ast.TreeInfo.PurePath => "PurityLevel.PurePath"
case ast.TreeInfo.IdempotentPath => "PurityLevel.IdempotentPath"
case _ => s"PurityLevel(${x.x})"

given Show[Showable] = ShowAny
given Show[Shown] = ShowAny
given Show[Int] = ShowAny
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i16954.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Test:
def test =
classOf[Test]

def blck =
class Blck
val cls = classOf[Blck]
cls

def expr =
class Expr
classOf[Expr] // was: "assertion failed: leak: Expr in { [..] }" crash

object Test extends Test:
def main(args: Array[String]): Unit =
assert(test.getName == "Test", test.getName)
assert(blck.getName == "Test$Blck$1", blck.getName)
assert(expr.getName == "Test$Expr$1", expr.getName)

0 comments on commit 92118c4

Please sign in to comment.