Skip to content

Commit 8ac4cf1

Browse files
committed
Fix a compiler assertion crash
1 parent 275cfa8 commit 8ac4cf1

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
@@ -2186,7 +2186,7 @@ object Types {
21862186
def designator: Designator
21872187
protected def designator_=(d: Designator): Unit
21882188

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

21912191
private var myName: Name | Null = null
21922192
private var lastDenotation: Denotation | Null = null
@@ -2693,7 +2693,7 @@ object Types {
26932693
this
26942694

26952695
/** A reference like this one, but with the given prefix. */
2696-
final def withPrefix(prefix: Type)(using Context): NamedType = {
2696+
final def withPrefix(prefix: Type)(using Context): Type = {
26972697
def reload(): NamedType = {
26982698
val lastSym = lastSymbol.nn
26992699
val allowPrivate = !lastSym.exists || lastSym.is(Private)
@@ -2706,6 +2706,7 @@ object Types {
27062706
NamedType(prefix, name, d)
27072707
}
27082708
if (prefix eq this.prefix) this
2709+
else if !NamedType.validPrefix(prefix) then UnspecifiedErrorType
27092710
else if (lastDenotation == null) NamedType(prefix, designator)
27102711
else designator match {
27112712
case sym: Symbol =>
@@ -2897,6 +2898,8 @@ object Types {
28972898
def apply(prefix: Type, designator: Name, denot: Denotation)(using Context): NamedType =
28982899
if (designator.isTermName) TermRef.apply(prefix, designator.asTermName, denot)
28992900
else TypeRef.apply(prefix, designator.asTypeName, denot)
2901+
2902+
def validPrefix(prefix: Type): Boolean = prefix.isValueType || (prefix eq NoPrefix)
29002903
}
29012904

29022905
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)