Skip to content

Commit ce38da4

Browse files
authored
Fix a compiler assertion crash (#16291)
2 parents e25362d + b31147c commit ce38da4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,7 +2188,7 @@ object Types {
21882188
def designator: Designator
21892189
protected def designator_=(d: Designator): Unit
21902190

2191-
assert(prefix.isValueType || (prefix eq NoPrefix), s"invalid prefix $prefix")
2191+
assert(NamedType.validPrefix(prefix), s"invalid prefix $prefix")
21922192

21932193
private var myName: Name | Null = null
21942194
private var lastDenotation: Denotation | Null = null
@@ -2698,7 +2698,7 @@ object Types {
26982698
this
26992699

27002700
/** A reference like this one, but with the given prefix. */
2701-
final def withPrefix(prefix: Type)(using Context): NamedType = {
2701+
final def withPrefix(prefix: Type)(using Context): Type = {
27022702
def reload(): NamedType = {
27032703
val lastSym = lastSymbol.nn
27042704
val allowPrivate = !lastSym.exists || lastSym.is(Private)
@@ -2711,6 +2711,7 @@ object Types {
27112711
NamedType(prefix, name, d)
27122712
}
27132713
if (prefix eq this.prefix) this
2714+
else if !NamedType.validPrefix(prefix) then UnspecifiedErrorType
27142715
else if (lastDenotation == null) NamedType(prefix, designator)
27152716
else designator match {
27162717
case sym: Symbol =>
@@ -2902,6 +2903,8 @@ object Types {
29022903
def apply(prefix: Type, designator: Name, denot: Denotation)(using Context): NamedType =
29032904
if (designator.isTermName) TermRef.apply(prefix, designator.asTermName, denot)
29042905
else TypeRef.apply(prefix, designator.asTypeName, denot)
2906+
2907+
def validPrefix(prefix: Type): Boolean = prefix.isValueType || (prefix eq NoPrefix)
29052908
}
29062909

29072910
object TermRef {

tests/neg/i12448.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Main {
2+
def mkArray[T <: A]: T#AType // error // error
3+
mkArray[Array] // was: "assertion failed: invalid prefix HKTypeLambda..."
4+
val x = mkArray[Array]
5+
}

0 commit comments

Comments
 (0)