From 1c56489b3e008ffb192443a1627df16f245a6c01 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 18 Jul 2009 15:19:55 +0000 Subject: Fix and post/neg test cases for #1878. --- src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 12 ++++++++++++ src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 ++++ test/files/neg/bug1878.check | 7 +++++++ test/files/neg/bug1878.scala | 10 ++++++++++ 4 files changed, 33 insertions(+) create mode 100644 test/files/neg/bug1878.check create mode 100644 test/files/neg/bug1878.scala diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index 3d023777f3..3eb6dc321b 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -276,6 +276,18 @@ abstract class TreeInfo { case _ => false } + /** The underlying pattern ignoring any bindings */ + def unbind(x: Tree): Tree = x match { + case Bind(_, y) => unbind(y) + case y => y + } + + /** Is this tree a Star(_) after removing bindings? */ + def isStar(x: Tree) = unbind(x) match { + case Star(_) => true + case _ => false + } + /** The method part of an application node */ def methPart(tree: Tree): Tree = tree match { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b1ed6da208..c2d69637b1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1607,6 +1607,10 @@ trait Typers { self: Analyzer => * @return ... */ def typedCase(cdef: CaseDef, pattpe: Type, pt: Type): CaseDef = { + // verify no _* except in last position + for (Apply(_, xs) <- cdef.pat ; x <- xs dropRight 1 ; if treeInfo isStar x) + error(x.pos, "_* may only come last") + val pat1: Tree = typedPattern(cdef.pat, pattpe) val guard1: Tree = if (cdef.guard == EmptyTree) EmptyTree else typed(cdef.guard, BooleanClass.tpe) diff --git a/test/files/neg/bug1878.check b/test/files/neg/bug1878.check new file mode 100644 index 0000000000..7b25a909a2 --- /dev/null +++ b/test/files/neg/bug1878.check @@ -0,0 +1,7 @@ +bug1878.scala:3: error: _* may only come last + val err1 = "" match { case Seq(f @ _*, ',') => f } + ^ +bug1878.scala:9: error: _* may only come last + val List(List(_*, arg2), _) = List(List(1,2,3), List(4,5,6)) + ^ +two errors found diff --git a/test/files/neg/bug1878.scala b/test/files/neg/bug1878.scala new file mode 100644 index 0000000000..ca76df082b --- /dev/null +++ b/test/files/neg/bug1878.scala @@ -0,0 +1,10 @@ +object Test extends Application { + // illegal + val err1 = "" match { case Seq(f @ _*, ',') => f } + + // no error + val List(List(arg1, _*), _) = List(List(1,2,3), List(4,5,6)) + + // illegal + val List(List(_*, arg2), _) = List(List(1,2,3), List(4,5,6)) +} \ No newline at end of file -- cgit v1.2.3