From cf38826926e59ac38b36912fab50420885385155 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 10 Aug 2020 17:35:47 +0200 Subject: [PATCH] Fix #9517: Do not print recursively ErrorType on -Xprint-types --- compiler/src/dotty/tools/dotc/core/Types.scala | 12 +++++++----- .../src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 ++ .../test/dotty/tools/dotc/CompilationTests.scala | 1 + tests/neg-custom-args/i9517.scala | 3 +++ 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 tests/neg-custom-args/i9517.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 777f43931e13..da5ce2eada1a 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -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" } diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 8b41983bad27..0d05928b1de6 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -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 => + "" // do not print previously reported error message because they may try to print this error type again recuresevely case tp: ErrorType => s"" case tp: WildcardType => diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 7b3fd7c6f04a..e927ba8d31a4 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -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"), diff --git a/tests/neg-custom-args/i9517.scala b/tests/neg-custom-args/i9517.scala new file mode 100644 index 000000000000..d1201d8ca39e --- /dev/null +++ b/tests/neg-custom-args/i9517.scala @@ -0,0 +1,3 @@ + +def test():Unit = foo({ case 1 => 10 }) // error +def foo(x: Any): Boolean = true