diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index c91412988e82..68ebdf74c4dd 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -2,7 +2,7 @@ package dotty.tools package dotc package core -import Contexts._, Types._, Symbols._, Names._, NameKinds.*, Flags._ +import Contexts._, Types._, Symbols._, Names._, NameKinds.*, Flags._, Constants.* import SymDenotations._ import util.Spans._ import util.Stats @@ -560,6 +560,9 @@ object TypeOps: widenUnions = tp.widenUnions)(using mapCtx) val lo1 = apply(lo) if (lo1 ne lo) lo1 else tp + case tp @ ConstantType(Constant(tp1: Type)) => + val tp2 = apply(tp1) + if tp2 eq tp1 then tp else ConstantType(Constant(tp2)) case _ => super.apply(tp) end apply diff --git a/tests/neg/i16954.check b/tests/neg/i16954.check new file mode 100644 index 000000000000..0cca1f21b925 --- /dev/null +++ b/tests/neg/i16954.check @@ -0,0 +1,4 @@ +-- [E170] Type Error: tests/neg/i16954.scala:4:12 ---------------------------------------------------------------------- +4 | classOf[y] // error: y is not a class type + | ^ + | y is not a class type diff --git a/tests/neg/i16954.scala b/tests/neg/i16954.scala new file mode 100644 index 000000000000..b5d6eb4bf179 --- /dev/null +++ b/tests/neg/i16954.scala @@ -0,0 +1,5 @@ +class Test: + def test = + type y + classOf[y] // error: y is not a class type +// was: "assertion failed: leak: y in { [..] }" crash after that error