From beabf5a40296e41aee7984b5b9801045203d5db0 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 1 Mar 2019 14:59:32 +0100 Subject: [PATCH 1/3] Fix #2950: prefer inner error The inner error is supposed to be more informative thus should be preferred. --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 4 +++- tests/neg/i2950.scala | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i2950.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 4900a99cda64..eecf8017f1cd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -940,7 +940,9 @@ 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) = + if (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/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 +} From d98c3ba7ce7eb27ce8c64b74b1791c991724c5cf Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 1 Mar 2019 15:35:16 +0100 Subject: [PATCH 2/3] Fix CI --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 2 +- .../test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala | 3 ++- tests/neg/parser-stability-10.scala | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index eecf8017f1cd..8a258a25c28e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -941,7 +941,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => val Apply(qual, args) = tree def notAnExtractor(tree: Tree) = - if (tree.tpe.isErroneous) tree + 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. 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/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 From 55e65cac5cd4e3a86d1b4fc317b6dfe5ad274712 Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Sat, 2 Mar 2019 22:36:10 +0100 Subject: [PATCH 3/3] Add comment to code --- compiler/src/dotty/tools/dotc/typer/Applications.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 8a258a25c28e..c636c573e171 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -941,6 +941,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => val Apply(qual, args) = tree 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))