@@ -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 {
0 commit comments