From b31147c67d5a4f432839ce1a190629191fcb7063 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 7 Nov 2022 08:54:45 +0000 Subject: [PATCH] Fix a compiler assertion crash --- compiler/src/dotty/tools/dotc/core/Types.scala | 7 +++++-- tests/neg/i12448.scala | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i12448.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index b4cc94b8c807..1e7dd0532a71 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2188,7 +2188,7 @@ object Types { def designator: Designator protected def designator_=(d: Designator): Unit - assert(prefix.isValueType || (prefix eq NoPrefix), s"invalid prefix $prefix") + assert(NamedType.validPrefix(prefix), s"invalid prefix $prefix") private var myName: Name | Null = null private var lastDenotation: Denotation | Null = null @@ -2698,7 +2698,7 @@ object Types { this /** A reference like this one, but with the given prefix. */ - final def withPrefix(prefix: Type)(using Context): NamedType = { + final def withPrefix(prefix: Type)(using Context): Type = { def reload(): NamedType = { val lastSym = lastSymbol.nn val allowPrivate = !lastSym.exists || lastSym.is(Private) @@ -2711,6 +2711,7 @@ object Types { NamedType(prefix, name, d) } if (prefix eq this.prefix) this + else if !NamedType.validPrefix(prefix) then UnspecifiedErrorType else if (lastDenotation == null) NamedType(prefix, designator) else designator match { case sym: Symbol => @@ -2902,6 +2903,8 @@ object Types { def apply(prefix: Type, designator: Name, denot: Denotation)(using Context): NamedType = if (designator.isTermName) TermRef.apply(prefix, designator.asTermName, denot) else TypeRef.apply(prefix, designator.asTypeName, denot) + + def validPrefix(prefix: Type): Boolean = prefix.isValueType || (prefix eq NoPrefix) } object TermRef { diff --git a/tests/neg/i12448.scala b/tests/neg/i12448.scala new file mode 100644 index 000000000000..e495cfd19f1d --- /dev/null +++ b/tests/neg/i12448.scala @@ -0,0 +1,5 @@ +object Main { + def mkArray[T <: A]: T#AType // error // error + mkArray[Array] // was: "assertion failed: invalid prefix HKTypeLambda..." + val x = mkArray[Array] +}