diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-10-08 21:20:23 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-10-09 09:32:45 +0200 |
commit | d0af55ce1ffb9d77e6a604edb41cda2b955e9f02 (patch) | |
tree | 66b9b41e4525287ef892d68ba140a804db475e25 | |
parent | acd77803f7da7c369f4ffdc70b5eeec4a23e35ae (diff) | |
download | scala-d0af55ce1ffb9d77e6a604edb41cda2b955e9f02.tar.gz scala-d0af55ce1ffb9d77e6a604edb41cda2b955e9f02.tar.bz2 scala-d0af55ce1ffb9d77e6a604edb41cda2b955e9f02.zip |
SI-7895 Avoid cascade of "symbol not found" in pattern matches
If we can't type check the `Foo` in `case Foo(a, b) => (a, b)`,
we should enter error symbols for `a` and `b` to avoid further
errors being reported in the case body.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 13 | ||||
-rw-r--r-- | test/files/neg/t0418.check | 5 | ||||
-rw-r--r-- | test/files/neg/t418.check | 5 | ||||
-rw-r--r-- | test/files/neg/t545.check | 5 | ||||
-rw-r--r-- | test/files/neg/t5903a.check | 5 | ||||
-rw-r--r-- | test/files/neg/t5903b.check | 5 | ||||
-rw-r--r-- | test/files/neg/t5903c.check | 5 | ||||
-rw-r--r-- | test/files/neg/t5903d.check | 5 | ||||
-rw-r--r-- | test/files/neg/t7895.check | 4 | ||||
-rw-r--r-- | test/files/neg/t7895.scala | 6 | ||||
-rw-r--r-- | test/files/neg/t997.check | 5 |
11 files changed, 28 insertions, 35 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index ecd987b031..e7371fa26b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2392,9 +2392,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper if (pat1.tpe.paramSectionCount > 0) pat1 modifyType (_.finalResultType) - for (bind @ Bind(name, _) <- cdef.pat) - if (name.toTermName != nme.WILDCARD && bind.symbol != null && bind.symbol != NoSymbol) - namer.enterIfNotThere(bind.symbol) + for (bind @ Bind(name, _) <- cdef.pat) { + val sym = bind.symbol + if (name.toTermName != nme.WILDCARD && sym != null) { + if (sym == NoSymbol) { + if (context.scope.lookup(name) == NoSymbol) + namer.enterInScope(context.owner.newErrorSymbol(name)) + } else + namer.enterIfNotThere(sym) + } + } val guard1: Tree = if (cdef.guard == EmptyTree) EmptyTree else typed(cdef.guard, BooleanTpe) diff --git a/test/files/neg/t0418.check b/test/files/neg/t0418.check index 4e9ad2f9ae..b95f8e4e1b 100644 --- a/test/files/neg/t0418.check +++ b/test/files/neg/t0418.check @@ -1,7 +1,4 @@ t0418.scala:2: error: not found: value Foo12340771 null match { case Foo12340771.Bar(x) => x } ^ -t0418.scala:2: error: not found: value x - null match { case Foo12340771.Bar(x) => x } - ^ -two errors found +one error found diff --git a/test/files/neg/t418.check b/test/files/neg/t418.check index 1489547823..1b99717b82 100644 --- a/test/files/neg/t418.check +++ b/test/files/neg/t418.check @@ -1,7 +1,4 @@ t418.scala:2: error: not found: value Foo12340771 null match { case Foo12340771.Bar(x) => x } ^ -t418.scala:2: error: not found: value x - null match { case Foo12340771.Bar(x) => x } - ^ -two errors found +one error found diff --git a/test/files/neg/t545.check b/test/files/neg/t545.check index 8ebbf9bdf6..aae575fa96 100644 --- a/test/files/neg/t545.check +++ b/test/files/neg/t545.check @@ -1,7 +1,4 @@ t545.scala:4: error: value blah is not a member of Test.Foo val x = foo.blah match { ^ -t545.scala:5: error: recursive value x needs type - case List(x) => x - ^ -two errors found +one error found diff --git a/test/files/neg/t5903a.check b/test/files/neg/t5903a.check index cbdcfd1bdd..2e5cc87167 100644 --- a/test/files/neg/t5903a.check +++ b/test/files/neg/t5903a.check @@ -1,7 +1,4 @@ Test_2.scala:4: error: wrong number of patterns for <$anon: AnyRef> offering (SomeTree.type, SomeTree.type): expected 2, found 3 case nq"$x + $y + $z" => println((x, y)) ^ -Test_2.scala:4: error: not found: value x - case nq"$x + $y + $z" => println((x, y)) - ^ -two errors found +one error found diff --git a/test/files/neg/t5903b.check b/test/files/neg/t5903b.check index faeb73ad03..e7637d3edb 100644 --- a/test/files/neg/t5903b.check +++ b/test/files/neg/t5903b.check @@ -3,7 +3,4 @@ Test_2.scala:4: error: type mismatch; required: String case t"$x" => println(x) ^ -Test_2.scala:4: error: not found: value x - case t"$x" => println(x) - ^ -two errors found +one error found diff --git a/test/files/neg/t5903c.check b/test/files/neg/t5903c.check index c9476edd11..05bd775d30 100644 --- a/test/files/neg/t5903c.check +++ b/test/files/neg/t5903c.check @@ -1,7 +1,4 @@ Test_2.scala:4: error: String is not supported case t"$x" => println(x) ^ -Test_2.scala:4: error: not found: value x - case t"$x" => println(x) - ^ -two errors found +one error found diff --git a/test/files/neg/t5903d.check b/test/files/neg/t5903d.check index d5d3fdcc28..9b8526b7f5 100644 --- a/test/files/neg/t5903d.check +++ b/test/files/neg/t5903d.check @@ -1,7 +1,4 @@ Test_2.scala:4: error: extractor macros can only expand into extractor calls case t"$x" => println(x) ^ -Test_2.scala:4: error: not found: value x - case t"$x" => println(x) - ^ -two errors found +one error found diff --git a/test/files/neg/t7895.check b/test/files/neg/t7895.check new file mode 100644 index 0000000000..1a58e24b77 --- /dev/null +++ b/test/files/neg/t7895.check @@ -0,0 +1,4 @@ +t7895.scala:4: error: not found: value Goop + case Goop(a, b, c) => Tuple2(a, b) + ^ +one error found diff --git a/test/files/neg/t7895.scala b/test/files/neg/t7895.scala new file mode 100644 index 0000000000..87a586a82d --- /dev/null +++ b/test/files/neg/t7895.scala @@ -0,0 +1,6 @@ +class A { + (null: Any) match { + // We don't want "symbol not found errors" for `a` and `b` in the case body. + case Goop(a, b, c) => Tuple2(a, b) + } +} diff --git a/test/files/neg/t997.check b/test/files/neg/t997.check index be1e92c369..8c41060ba2 100644 --- a/test/files/neg/t997.check +++ b/test/files/neg/t997.check @@ -4,7 +4,4 @@ t997.scala:13: error: wrong number of patterns for object Foo offering (String, t997.scala:13: error: wrong number of patterns for object Foo offering (String, String): expected 2, found 3 "x" match { case Foo(a, b, c) => Console.println((a,b,c)) } ^ -t997.scala:13: error: not found: value a -"x" match { case Foo(a, b, c) => Console.println((a,b,c)) } - ^ -three errors found +two errors found |