Skip to content

Port "illegal cyclic type reference" error to new scheme #7465

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 1, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
StaticFieldsShouldPrecedeNonStaticID,
IllegalSuperAccessorID,
TraitParameterUsedAsParentPrefixID,
UnknownNamedEnclosingClassOrObjectID
UnknownNamedEnclosingClassOrObjectID,
IllegalCyclicTypeReferenceID

def errorNumber = ordinal - 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -2392,4 +2392,11 @@ object messages {
|current scope.
""".stripMargin
}

case class IllegalCyclicTypeReference(sym: Symbol, where: String, lastChecked: Type)(implicit val ctx: Context)
extends Message(IllegalCyclicTypeReferenceID) {
val kind: String = "Type"
val msg: String = i"illegal cyclic type reference: ${where} ${hl(lastChecked.show)} of $sym refers back to the type itself"
val explanation: String = ""
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ object Checking {
catch {
case ex: CyclicReference =>
if (reportErrors)
errorType(i"illegal cyclic reference: ${checker.where} ${checker.lastChecked} of $sym refers back to the type itself", sym.sourcePos)
errorType(IllegalCyclicTypeReference(sym, checker.where, checker.lastChecked), sym.sourcePos)
else info
}
}
Expand Down
15 changes: 15 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1672,4 +1672,19 @@ class ErrorMessagesTests extends ErrorMessagesTest {
val UnknownNamedEnclosingClassOrObject(name) :: Nil = messages
assertEquals("doesNotExist", name.show)
}

@Test def illegalCyclicTypeReference() =
checkMessagesAfter(RefChecks.name) {
"""
|type X = List[X]
""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
assertMessageCount(1, messages)
val IllegalCyclicTypeReference(sym, where, lastChecked) :: Nil = messages
assertEquals("type X", sym.show)
assertEquals("alias", where)
assertEquals("List[X]", lastChecked.show)
}
}