Skip to content

Fix #9517: Do not print contents of ErrorType on -Xprint-types #9527

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
Aug 31, 2020
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
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4706,15 +4706,17 @@ object Types {

object ErrorType:
def apply(m: Message)(using Context): ErrorType =
val et = new ErrorType:
def msg(using Context): Message =
ctx.base.errorTypeMsg.get(this) match
case Some(m) => m
case None => "error message from previous run no longer available"
val et = new PreviousErrorType
ctx.base.errorTypeMsg(et) = m
et
end ErrorType

class PreviousErrorType extends ErrorType:
def msg(using Context): Message =
ctx.base.errorTypeMsg.get(this) match
case Some(m) => m
case None => "error message from previous run no longer available"

object UnspecifiedErrorType extends ErrorType {
override def msg(using Context): Message = "unspecified error"
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
keywordStr(" match ") ~ "{" ~ casesText ~ "}" ~
(" <: " ~ toText(bound) provided !bound.isAny)
}.close
case tp: PreviousErrorType if ctx.settings.XprintTypes.value =>
"<error>" // do not print previously reported error message because they may try to print this error type again recuresevely
case tp: ErrorType =>
s"<error ${tp.msg.rawMessage}>"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The infinite recursion happens here. The message may print a tree that contains this error type again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlainPrinter already has some logic to avoid infinite loops with limiter and maxToTextRecursions, it'd be good to see if we can extend that to also account for the loops here

case tp: WildcardType =>
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class CompilationTests extends ParallelTesting {
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes),
compileFile("tests/neg-custom-args/i9517.scala", defaultOptions.and("-Xprint-types")),
compileFile("tests/neg-custom-args/interop-polytypes.scala", allowDeepSubtypes.and("-Yexplicit-nulls")),
compileFile("tests/neg-custom-args/conditionalWarnings.scala", allowDeepSubtypes.and("-deprecation").and("-Xfatal-warnings")),
compileFilesInDir("tests/neg-custom-args/isInstanceOf", allowDeepSubtypes and "-Xfatal-warnings"),
Expand Down
3 changes: 3 additions & 0 deletions tests/neg-custom-args/i9517.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def test():Unit = foo({ case 1 => 10 }) // error
def foo(x: Any): Boolean = true