Skip to content

Commit 0bbafae

Browse files
natsukagamitgodzik
authored andcommitted
Fix insufficient number width allocated when using -print-lines (scala#23336)
[Cherry-picked 7d4fb6f]
1 parent a8b329d commit 0bbafae

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ object Texts {
139139

140140
def mkString(width: Int, withLineNumbers: Boolean): String = {
141141
val sb = new StringBuilder
142-
val numberWidth = if (withLineNumbers) (2 * maxLine.toString.length) + 2 else 0
142+
// width display can be upto a range "n-n" where 1 <= n <= maxLine+1
143+
val numberWidth = if (withLineNumbers) (2 * (maxLine + 1).toString.length) + 2 else 0
143144
layout(width - numberWidth).print(sb, numberWidth)
144145
sb.toString
145146
}

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class TypeMismatch(val found: Type, expected: Type, val inTree: Option[untpd.Tre
352352
++ addenda.dropWhile(_.isEmpty).headOption.getOrElse(importSuggestions)
353353

354354
override def explain(using Context) =
355-
val treeStr = inTree.map(x => s"\nTree: ${x.show}").getOrElse("")
355+
val treeStr = inTree.map(x => s"\nTree:\n\n${x.show}\n").getOrElse("")
356356
treeStr + "\n" + super.explain
357357

358358
end TypeMismatch

tests/neg/19680.check

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
| Explanation (enabled by `-explain`)
88
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99
|
10-
| Tree: new Config()
10+
| Tree:
11+
|
12+
| new Config()
13+
|
1114
| I tried to show that
1215
| Config
1316
| conforms to

tests/neg/19680b.check

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
| Explanation (enabled by `-explain`)
88
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99
|
10-
| Tree: "hello"
10+
| Tree:
11+
|
12+
| "hello"
13+
|
1114
| I tried to show that
1215
| ("hello" : String)
1316
| conforms to

tests/neg/hidden-type-errors.check

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
| Explanation (enabled by `-explain`)
88
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99
|
10-
| Tree: t12717.A.bar("XXX")
10+
| Tree:
11+
|
12+
| t12717.A.bar("XXX")
13+
|
1114
| I tried to show that
1215
| String
1316
| conforms to

tests/neg/i18737.check

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
| Explanation (enabled by `-explain`)
88
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99
|
10-
| Tree: v
10+
| Tree:
11+
|
12+
| v
13+
|
1114
| I tried to show that
1215
| (v : String & Long)
1316
| conforms to
@@ -32,7 +35,10 @@
3235
| Explanation (enabled by `-explain`)
3336
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3437
|
35-
| Tree: v
38+
| Tree:
39+
|
40+
| v
41+
|
3642
| I tried to show that
3743
| (v : String | Long)
3844
| conforms to

0 commit comments

Comments
 (0)