From c1327dcd99a6ca84d2550b8e4894ec7ee5ee2420 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 20 Apr 2013 11:52:21 +0200 Subject: SI-6675 Avoid spurious warning about pattern bind arity. In 692372ce, we added a warning (under -Xlint) when binding a `TupleN` in to a single pattern binder, which wasn't allowed before 2.10.0, and more often than not represents a bug. However, that warning overstretched, and warned even when using a Tuple Pattern to bind to the elements of such a value. This commit checks for this case, and avoids the spurious warnings. A new test case is added for this case to go with the existing test for SI-6675: $ ./tools/partest-ack 6675 % tests-with-matching-paths ... 3 % tests-with-matching-code ... 2 # 3 tests to run. test/partest --show-diff --show-log \ test/files/neg/t6675-old-patmat.scala \ test/files/neg/t6675.scala \ test/files/pos/t6675.scala \ "" Testing individual files testing: [...]/files/pos/t6675.scala [ OK ] Testing individual files testing: [...]/files/neg/t6675-old-patmat.scala [ OK ] testing: [...]/files/neg/t6675.scala [ OK ] All of 3 tests were successful (elapsed time: 00:00:03) --- src/reflect/scala/reflect/internal/TreeInfo.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/reflect') diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala index 3e74b5d22d..fa4441e513 100644 --- a/src/reflect/scala/reflect/internal/TreeInfo.scala +++ b/src/reflect/scala/reflect/internal/TreeInfo.scala @@ -17,7 +17,7 @@ abstract class TreeInfo { val global: SymbolTable import global._ - import definitions.{ isVarArgsList, isCastSymbol, ThrowableClass, TupleClass, MacroContextClass, MacroContextPrefixType } + import definitions.{ isTupleSymbol, isVarArgsList, isCastSymbol, ThrowableClass, TupleClass, MacroContextClass, MacroContextPrefixType } /* Does not seem to be used. Not sure what it does anyway. def isOwnerDefinition(tree: Tree): Boolean = tree match { @@ -515,6 +515,20 @@ abstract class TreeInfo { case _ => false } + /** + * {{{ + * //------------------------ => effectivePatternArity(args) + * case Extractor(a) => 1 + * case Extractor(a, b) => 2 + * case Extractor((a, b)) => 2 + * case Extractor(a @ (b, c)) => 2 + * }}} + */ + def effectivePatternArity(args: List[Tree]): Int = (args.map(unbind) match { + case Apply(fun, xs) :: Nil if isTupleSymbol(fun.symbol) => xs + case xs => xs + }).length + // used in the symbols for labeldefs and valdefs emitted by the pattern matcher // tailcalls, cps,... use this flag combination to detect translated matches -- cgit v1.2.3