diff --git a/compiler/src/dotty/tools/dotc/printing/Texts.scala b/compiler/src/dotty/tools/dotc/printing/Texts.scala index 7df464ae74b8..9a3aac39ed18 100644 --- a/compiler/src/dotty/tools/dotc/printing/Texts.scala +++ b/compiler/src/dotty/tools/dotc/printing/Texts.scala @@ -106,11 +106,13 @@ object Texts { case Str(s, lines) => if (numberWidth != 0) { val ln = lines.show - val pad = (numberWidth - ln.length - 1) - assert(pad >= 0) - sb.append(" " * pad) - sb.append(ln) - sb.append("|") + if (ln.nonEmpty) { + val pad = (numberWidth - ln.length - 1) + assert(pad >= 0) + sb.append(" " * pad) + sb.append(ln) + sb.append("|") + } } sb.append(s) case _ => diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index a9e679eb6e95..a9f376d3cda6 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -182,6 +182,7 @@ class CompilationTests { compileFile("tests/neg-custom-args/i7314.scala", defaultOptions.and("-Xfatal-warnings", "-source", "future")), compileFile("tests/neg-custom-args/feature-shadowing.scala", defaultOptions.and("-Xfatal-warnings", "-feature")), compileDir("tests/neg-custom-args/hidden-type-errors", defaultOptions.and("-explain")), + compileFile("tests/neg-custom-args/i13026.scala", defaultOptions.and("-print-lines")), ).checkExpectedErrors() } diff --git a/tests/neg-custom-args/i13026.check b/tests/neg-custom-args/i13026.check new file mode 100644 index 000000000000..ec729f1968b1 --- /dev/null +++ b/tests/neg-custom-args/i13026.check @@ -0,0 +1,18 @@ +-- [E007] Type Mismatch Error: tests/neg-custom-args/i13026.scala:1:13 ------------------------------------------------- +1 |val x: Int = "not an int" // error + | ^^^^^^^^^^^^ + | Found: ("not an int" : String) + | Required: Int + +longer explanation available when compiling with `-explain` +-- [E007] Type Mismatch Error: tests/neg-custom-args/i13026.scala:2:13 ------------------------------------------------- +2 |val y: Int = "not an int" // error + | ^^^^^^^^^^^^ + | Found: ("not an int" : String) + | Required: Int + +longer explanation available when compiling with `-explain` +-- [E008] Not Found Error: tests/neg-custom-args/i13026.scala:3:20 ----------------------------------------------------- +3 |def foo(x: Any) = x.foo // error + | ^^^^^ + | value foo is not a member of Any diff --git a/tests/neg-custom-args/i13026.scala b/tests/neg-custom-args/i13026.scala new file mode 100644 index 000000000000..9ecf909f7122 --- /dev/null +++ b/tests/neg-custom-args/i13026.scala @@ -0,0 +1,3 @@ +val x: Int = "not an int" // error +val y: Int = "not an int" // error +def foo(x: Any) = x.foo // error