Skip to content

Commit 5b1f277

Browse files
authored
Merge pull request #6001 from dotty-staging/fix-i2950
Fix #2950: prefer inner error
2 parents 2a7edab + 55e65ca commit 5b1f277

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
940940
def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = track("typedUnApply") {
941941
val Apply(qual, args) = tree
942942

943-
def notAnExtractor(tree: Tree) = errorTree(tree, NotAnExtractor(qual))
943+
def notAnExtractor(tree: Tree) =
944+
// prefer inner errors
945+
// e.g. report not found ident instead of not an extractor in tests/neg/i2950.scala
946+
if (!tree.tpe.isError && tree.tpe.isErroneous) tree
947+
else errorTree(tree, NotAnExtractor(qual))
944948

945949
/** If this is a term ref tree, try to typecheck with its type name.
946950
* If this refers to a type alias, follow the alias, and if

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,8 @@ class ErrorMessagesTests extends ErrorMessagesTest {
15541554
@Test def notAnExtractor() =
15551555
checkMessagesAfter(FrontEnd.name) {
15561556
"""
1557-
| class Foo
1557+
| trait Foo
1558+
| object Foo
15581559
| object Test {
15591560
| def test(foo: Foo) = foo match {
15601561
| case Foo(name) => ???

tests/neg/i2950.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class T1 {
2+
case class Foo(x: Int, xs1: List[String], xs2: List[String])
3+
}
4+
5+
object T2 {
6+
val foo: T1#Foo = ???
7+
8+
val Foo(x1, xs1, xs2) = foo // error
9+
}

tests/neg/parser-stability-10.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ def unapply(i1: Int)(i6: List[Int]): Int = {
99
} // error
1010
object i5 {
1111
import collection.mutable._
12-
try { ??? mutable { case i1(i5, i3, i4) => i5 }} // error // error // error
12+
try { ??? mutable { case i1(i5, i3, i4) => i5 }} // error // error
1313
}
1414
// error

0 commit comments

Comments
 (0)