Skip to content

Fix a compiler assertion crash #16291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 =>
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i12448.scala
Original file line number Diff line number Diff line change
@@ -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]
}