diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 4900a99cda64..c636c573e171 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -940,7 +940,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic => def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = track("typedUnApply") { val Apply(qual, args) = tree - def notAnExtractor(tree: Tree) = errorTree(tree, NotAnExtractor(qual)) + def notAnExtractor(tree: Tree) = + // prefer inner errors + // e.g. report not found ident instead of not an extractor in tests/neg/i2950.scala + if (!tree.tpe.isError && tree.tpe.isErroneous) tree + else errorTree(tree, NotAnExtractor(qual)) /** If this is a term ref tree, try to typecheck with its type name. * If this refers to a type alias, follow the alias, and if diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 8d5f692aa65d..cac9f844895d 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -1554,7 +1554,8 @@ class ErrorMessagesTests extends ErrorMessagesTest { @Test def notAnExtractor() = checkMessagesAfter(FrontEnd.name) { """ - | class Foo + | trait Foo + | object Foo | object Test { | def test(foo: Foo) = foo match { | case Foo(name) => ??? diff --git a/tests/neg/i2950.scala b/tests/neg/i2950.scala new file mode 100644 index 000000000000..86733f1ef346 --- /dev/null +++ b/tests/neg/i2950.scala @@ -0,0 +1,9 @@ +class T1 { + case class Foo(x: Int, xs1: List[String], xs2: List[String]) +} + +object T2 { + val foo: T1#Foo = ??? + + val Foo(x1, xs1, xs2) = foo // error +} diff --git a/tests/neg/parser-stability-10.scala b/tests/neg/parser-stability-10.scala index 661e386b440e..f72062a7f726 100644 --- a/tests/neg/parser-stability-10.scala +++ b/tests/neg/parser-stability-10.scala @@ -9,6 +9,6 @@ def unapply(i1: Int)(i6: List[Int]): Int = { } // error object i5 { import collection.mutable._ - try { ??? mutable { case i1(i5, i3, i4) => i5 }} // error // error // error + try { ??? mutable { case i1(i5, i3, i4) => i5 }} // error // error } // error \ No newline at end of file