Skip to content

Commit 3fb0516

Browse files
Merge pull request #9527 from dotty-staging/fix-#9517
Fix #9517: Do not print contents of ErrorType on -Xprint-types
2 parents ac850b9 + cf38826 commit 3fb0516

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,15 +4756,17 @@ object Types {
47564756

47574757
object ErrorType:
47584758
def apply(m: Message)(using Context): ErrorType =
4759-
val et = new ErrorType:
4760-
def msg(using Context): Message =
4761-
ctx.base.errorTypeMsg.get(this) match
4762-
case Some(m) => m
4763-
case None => "error message from previous run no longer available"
4759+
val et = new PreviousErrorType
47644760
ctx.base.errorTypeMsg(et) = m
47654761
et
47664762
end ErrorType
47674763

4764+
class PreviousErrorType extends ErrorType:
4765+
def msg(using Context): Message =
4766+
ctx.base.errorTypeMsg.get(this) match
4767+
case Some(m) => m
4768+
case None => "error message from previous run no longer available"
4769+
47684770
object UnspecifiedErrorType extends ErrorType {
47694771
override def msg(using Context): Message = "unspecified error"
47704772
}

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
183183
keywordStr(" match ") ~ "{" ~ casesText ~ "}" ~
184184
(" <: " ~ toText(bound) provided !bound.isAny)
185185
}.close
186+
case tp: PreviousErrorType if ctx.settings.XprintTypes.value =>
187+
"<error>" // do not print previously reported error message because they may try to print this error type again recuresevely
186188
case tp: ErrorType =>
187189
s"<error ${tp.msg.rawMessage}>"
188190
case tp: WildcardType =>

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class CompilationTests extends ParallelTesting {
149149
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes),
150150
compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes),
151151
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes),
152+
compileFile("tests/neg-custom-args/i9517.scala", defaultOptions.and("-Xprint-types")),
152153
compileFile("tests/neg-custom-args/interop-polytypes.scala", allowDeepSubtypes.and("-Yexplicit-nulls")),
153154
compileFile("tests/neg-custom-args/conditionalWarnings.scala", allowDeepSubtypes.and("-deprecation").and("-Xfatal-warnings")),
154155
compileFilesInDir("tests/neg-custom-args/isInstanceOf", allowDeepSubtypes and "-Xfatal-warnings"),

tests/neg-custom-args/i9517.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def test():Unit = foo({ case 1 => 10 }) // error
3+
def foo(x: Any): Boolean = true

0 commit comments

Comments
 (0)