Skip to content

Commit f0c9ff8

Browse files
committed
Better positions on errorTermTree
1 parent 29f9d33 commit f0c9ff8

16 files changed

+60
-62
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ object Parsers {
377377
false
378378
}
379379

380-
def errorTermTree: Literal = atSpan(in.offset) { Literal(Constant(null)) }
380+
def errorTermTree(start: Offset): Literal = atSpan(start, in.offset, in.offset) { Literal(Constant(null)) }
381381

382382
private var inFunReturnType = false
383383
private def fromWithinReturnType[T](body: => T): T = {
@@ -1931,7 +1931,7 @@ object Parsers {
19311931
PolyFunction(tparams, body)
19321932
else {
19331933
syntaxError("Implementation restriction: polymorphic function literals must have a value parameter", arrowOffset)
1934-
errorTermTree
1934+
errorTermTree(arrowOffset)
19351935
}
19361936
}
19371937
case _ =>
@@ -2298,8 +2298,9 @@ object Parsers {
22982298
in.nextToken()
22992299
simpleExpr(location)
23002300
else
2301+
val start = in.lastOffset
23012302
syntaxErrorOrIncomplete(IllegalStartSimpleExpr(tokenString(in.token)), expectedOffset)
2302-
errorTermTree
2303+
errorTermTree(start)
23032304
}
23042305
simpleExprRest(t, location, canApply)
23052306
}
@@ -2738,8 +2739,9 @@ object Parsers {
27382739
case _ =>
27392740
if (isLiteral) literal(inPattern = true)
27402741
else {
2742+
val start = in.lastOffset
27412743
syntaxErrorOrIncomplete(IllegalStartOfSimplePattern(), expectedOffset)
2742-
errorTermTree
2744+
errorTermTree(start)
27432745
}
27442746
}
27452747

@@ -3314,8 +3316,9 @@ object Parsers {
33143316
}
33153317
val rhs2 =
33163318
if rhs.isEmpty && !isAllIds then
3319+
val start = in.lastOffset
33173320
syntaxError(ExpectedTokenButFound(EQUALS, in.token), Span(in.lastOffset))
3318-
errorTermTree
3321+
errorTermTree(start)
33193322
else
33203323
rhs
33213324
PatDef(mods, lhs, tpt, rhs2)
@@ -3483,11 +3486,12 @@ object Parsers {
34833486
case GIVEN =>
34843487
givenDef(start, mods, atSpan(in.skipToken()) { Mod.Given() })
34853488
case _ =>
3489+
val start = in.lastOffset
34863490
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
34873491
mods.annotations match {
34883492
case head :: Nil => head
34893493
case Nil => EmptyTree
3490-
case all => Block(all, errorTermTree)
3494+
case all => Block(all, errorTermTree(start))
34913495
}
34923496
}
34933497

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object MarkupParsers {
131131
try handle.parseAttribute(Span(start, curOffset, mid), tmp)
132132
catch {
133133
case e: RuntimeException =>
134-
errorAndResult("error parsing attribute value", parser.errorTermTree)
134+
errorAndResult("error parsing attribute value", parser.errorTermTree(parser.in.offset))
135135
}
136136

137137
case '{' =>
@@ -334,7 +334,7 @@ object MarkupParsers {
334334
finally parser.in.resume(saved)
335335

336336
if (output == null)
337-
parser.errorTermTree
337+
parser.errorTermTree(parser.in.offset)
338338
else
339339
output
340340
}

language-server/test/dotty/tools/languageserver/DiagnosticsTest.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class DiagnosticsTest {
2121
| Nil.map(x => x).filter(x$m1 =>$m2)$m3
2222
|}""".withSource
2323
.diagnostics(m1,
24-
(m2 to m2, "expression expected but ')' found", Error, Some(IllegalStartSimpleExprID)),
25-
(m1 to m1, """Found: Null
26-
|Required: Boolean""".stripMargin, Error, Some(TypeMismatchID))
24+
(m2 to m2, "expression expected but ')' found", Error, Some(IllegalStartSimpleExprID))
2725
)
2826

2927
@Test def diagnosticPureExpression: Unit =

tests/neg/arg-eof.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
object Test:
22
case class Widget(name: String, other: Int = 5)
3-
Widget(name = "foo", // error // error
3+
Widget(name = "foo", // error

tests/neg/errpos.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object Test {
1010
val b = type // error: expression expected (on "type")
1111

1212
1 match {
13-
case // error: pattern expected // error: cannot compare with Null
13+
case // error: pattern expected
1414
case 2 => ""
1515
}
16-
}
16+
}

tests/neg/i12150.check

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,3 @@
44
| expression expected but end found
55
|
66
| longer explanation available when compiling with `-explain`
7-
-- [E129] Potential Issue Warning: tests/neg/i12150.scala:1:11 ---------------------------------------------------------
8-
1 |def f: Unit = // error
9-
| ^
10-
| A pure expression does nothing in statement position; you may be omitting necessary parentheses
11-
|
12-
| longer explanation available when compiling with `-explain`

tests/neg/i1846.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ object Test {
33
val x = 42
44
val Y = "42"
55

6-
x match { case { 42 } => () } // error // error
7-
x match { case { 42.toString } => () } // error // error
8-
x match { case { 42 }.toString => () } // error // error
6+
x match { case { 42 } => () } // error
7+
x match { case { 42.toString } => () } // error
8+
x match { case { 42 }.toString => () } // error
99
x match { case "42".toInt => () } // error
10-
x match { case { "42".toInt } => () } // error // error
11-
x match { case { "42" }.toInt => () } // error // error
12-
x match { case { "42".toInt } => () } // error // error
10+
x match { case { "42".toInt } => () } // error
11+
x match { case { "42" }.toInt => () } // error
12+
x match { case { "42".toInt } => () } // error
1313
x match { case Y => () } // error
14-
x match { case { Y.toInt } => () } // error // error
15-
x match { case { Y }.toInt => () } // error // error
16-
x match { case { Y }.toString => () } // error // error
17-
x match { case { Y.toString } => () } // error // error
14+
x match { case { Y.toInt } => () } // error
15+
x match { case { Y }.toInt => () } // error
16+
x match { case { Y }.toString => () } // error
17+
x match { case { Y.toString } => () } // error
1818
}
1919
}

tests/neg/i3812.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ object Test {
33
val x = 42
44
val Y = "42"
55

6-
x match { case { 42 } => () } // error // error
7-
x match { case { "42".toInt } => () } // error // error
8-
x match { case { "42" }.toInt => () } // error // error
9-
x match { case { "42".toInt } => () } // error // error
10-
x match { case { Y.toInt } => () } // error // error
11-
x match { case { Y }.toInt => () } // error // error
6+
x match { case { 42 } => () } // error
7+
x match { case { "42".toInt } => () } // error
8+
x match { case { "42" }.toInt => () } // error
9+
x match { case { "42".toInt } => () } // error
10+
x match { case { Y.toInt } => () } // error
11+
x match { case { Y }.toInt => () } // error
1212
}
1313
}

tests/neg/i5004.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object i0 {
22
1 match {
33
def this(): Int // error
4-
def this()
4+
def this() // error
5+
}
56
}
6-
}

tests/neg/i7742.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
object A {
2-
for // error // error
3-
}
2+
for // error
3+
}

0 commit comments

Comments
 (0)