Skip to content

Commit d253777

Browse files
committed
Fix #9517: Do not print recursively ErrorType on -Xprint-types
1 parent 844be0d commit d253777

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
@@ -4706,15 +4706,17 @@ object Types {
47064706

47074707
object ErrorType:
47084708
def apply(m: Message)(using Context): ErrorType =
4709-
val et = new ErrorType:
4710-
def msg(using Context): Message =
4711-
ctx.base.errorTypeMsg.get(this) match
4712-
case Some(m) => m
4713-
case None => "error message from previous run no longer available"
4709+
val et = new PreviousErrorType
47144710
ctx.base.errorTypeMsg(et) = m
47154711
et
47164712
end ErrorType
47174713

4714+
class PreviousErrorType extends ErrorType:
4715+
def msg(using Context): Message =
4716+
ctx.base.errorTypeMsg.get(this) match
4717+
case Some(m) => m
4718+
case None => "error message from previous run no longer available"
4719+
47184720
object UnspecifiedErrorType extends ErrorType {
47194721
override def msg(using Context): Message = "unspecified error"
47204722
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
177177
keywordStr(" match ") ~ "{" ~ casesText ~ "}" ~
178178
(" <: " ~ toText(bound) provided !bound.isAny)
179179
}.close
180+
case tp: PreviousErrorType =>
181+
"<error>"
180182
case tp: ErrorType =>
181183
s"<error ${tp.msg.rawMessage}>"
182184
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)