diff --git a/compiler/src/dotty/tools/dotc/printing/Texts.scala b/compiler/src/dotty/tools/dotc/printing/Texts.scala index 203e3fd58155..a4b2e3305742 100644 --- a/compiler/src/dotty/tools/dotc/printing/Texts.scala +++ b/compiler/src/dotty/tools/dotc/printing/Texts.scala @@ -139,7 +139,8 @@ object Texts { def mkString(width: Int = Int.MaxValue, withLineNumbers: Boolean = false): String = { val sb = new StringBuilder - val numberWidth = if (withLineNumbers) (2 * maxLine.toString.length) + 2 else 0 + // width display can be upto a range "n-n" where 1 <= n <= maxLine+1 + val numberWidth = if (withLineNumbers) (2 * (maxLine + 1).toString.length) + 2 else 0 layout(width - numberWidth).print(sb, numberWidth) sb.toString } diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 44b97790c849..7c197e9642e4 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -357,7 +357,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre ++ addenda.dropWhile(_.isEmpty).headOption.getOrElse(importSuggestions) override def explain(using Context) = - val treeStr = inTree.map(x => s"\nTree: ${x.show}").getOrElse("") + val treeStr = inTree.map(x => s"\nTree:\n\n${x.show}\n").getOrElse("") treeStr + "\n" + super.explain end TypeMismatch @@ -3539,4 +3539,4 @@ final class IllegalContextBounds(using Context) extends SyntaxMsg(IllegalContext override protected def explain(using Context): String = "" -end IllegalContextBounds \ No newline at end of file +end IllegalContextBounds diff --git a/tests/neg/19680.check b/tests/neg/19680.check index 5bdaaad99c2a..f7547d6a4eee 100644 --- a/tests/neg/19680.check +++ b/tests/neg/19680.check @@ -7,7 +7,10 @@ | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - | Tree: new Config() + | Tree: + | + | new Config() + | | I tried to show that | Config | conforms to diff --git a/tests/neg/19680b.check b/tests/neg/19680b.check index 06ff26ee3289..6c5c60b29dee 100644 --- a/tests/neg/19680b.check +++ b/tests/neg/19680b.check @@ -7,7 +7,10 @@ | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - | Tree: "hello" + | Tree: + | + | "hello" + | | I tried to show that | ("hello" : String) | conforms to diff --git a/tests/neg/hidden-type-errors.check b/tests/neg/hidden-type-errors.check index 2f4a1748dc67..47f5d454c297 100644 --- a/tests/neg/hidden-type-errors.check +++ b/tests/neg/hidden-type-errors.check @@ -7,7 +7,10 @@ | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - | Tree: t12717.A.bar("XXX") + | Tree: + | + | t12717.A.bar("XXX") + | | I tried to show that | String | conforms to diff --git a/tests/neg/i18737.check b/tests/neg/i18737.check index f2067ad017cd..4f9ac50a784b 100644 --- a/tests/neg/i18737.check +++ b/tests/neg/i18737.check @@ -7,7 +7,10 @@ | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - | Tree: v + | Tree: + | + | v + | | I tried to show that | (v : String & Long) | conforms to @@ -32,7 +35,10 @@ | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | - | Tree: v + | Tree: + | + | v + | | I tried to show that | (v : String | Long) | conforms to