Skip to content

Commit 276cf27

Browse files
committed
Better error recovery
The test case is tests/neg/deferred-patdef.scala
1 parent 70e390e commit 276cf27

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,9 +3225,13 @@ object Parsers {
32253225
case IdPattern(id, t) => t.isEmpty
32263226
case _ => false
32273227
}
3228-
if rhs.isEmpty && !isAllIds then
3229-
syntaxError(ExpectedTokenButFound(EQUALS, in.token), Span(in.lastOffset))
3230-
PatDef(mods, lhs, tpt, rhs)
3228+
val rhs2 =
3229+
if rhs.isEmpty && !isAllIds then
3230+
syntaxError(ExpectedTokenButFound(EQUALS, in.token), Span(in.lastOffset))
3231+
errorTermTree
3232+
else
3233+
rhs
3234+
PatDef(mods, lhs, tpt, rhs2)
32313235
}
32323236
}
32333237

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ trait Checking {
696696

697697
def recur(pat: Tree, pt: Type): Boolean =
698698
!sourceVersion.isAtLeast(`3.1`) || // only for 3.1 for now since mitigations work only after this PR
699-
pt.widen.hasAnnotation(defn.UncheckedAnnot) || {
699+
pt.hasAnnotation(defn.UncheckedAnnot) || {
700700
patmatch.println(i"check irrefutable $pat: ${pat.tpe} against $pt")
701701
pat match {
702702
case Bind(_, pat1) =>

tests/neg-custom-args/infix.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test() = {
5858
val Pair(_, _) = p
5959
val _ Pair _ = p // error
6060
val _ `Pair` _ = p // OK
61-
val (_ PP _): @unchecked = p // OK
61+
val (_ PP _) = p: @unchecked // OK
6262

6363
val q = Q(1, 2)
6464
val Q(_, _) = q

0 commit comments

Comments
 (0)