Skip to content

Commit 86f9ca1

Browse files
committed
Fix #9517: Do not print contents of ErrorType on -Xprint-types
1 parent 844be0d commit 86f9ca1

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4706,11 +4706,12 @@ object Types {
47064706

47074707
object ErrorType:
47084708
def apply(m: Message)(using Context): ErrorType =
4709-
val et = new ErrorType:
4709+
class PreviousErrorType extends ErrorType:
47104710
def msg(using Context): Message =
47114711
ctx.base.errorTypeMsg.get(this) match
47124712
case Some(m) => m
47134713
case None => "error message from previous run no longer available"
4714+
val et = new PreviousErrorType
47144715
ctx.base.errorTypeMsg(et) = m
47154716
et
47164717
end ErrorType

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
695695
}
696696
else tp2
697697

698-
if (!suppressTypes)
698+
if tp3.isInstanceOf[ErrorType] then
699+
txt = ("<" ~ txt ~ ":ERROR>").close
700+
else if !suppressTypes then
699701
txt = ("<" ~ txt ~ ":" ~ toText(tp3) ~ ">").close
700702
else if (tree.isType && !homogenizedView)
701703
txt = toText(tp3)

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)