summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-03-27 08:13:24 +0100
committerJason Zaugg <jzaugg@gmail.com>2013-03-27 08:16:41 +0100
commitc3ad5af27df1b365873870827a6093f630881343 (patch)
tree6832b696164a8162cc7fe7b95d0acbba2e1b8dba /src
parent2e0be8323bdef5582a0f5af84b3de83fcc338be4 (diff)
downloadscala-c3ad5af27df1b365873870827a6093f630881343.tar.gz
scala-c3ad5af27df1b365873870827a6093f630881343.tar.bz2
scala-c3ad5af27df1b365873870827a6093f630881343.zip
SI-7290 Minor cleanups driven by review comments.
- make a def a val, we only need to compute it once - add a clarifying comment - only report the first duplicate
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
index 23889058d3..c570dd8572 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala
@@ -16,9 +16,9 @@ import scala.reflect.internal.util.NoPosition
/** Optimize and analyze matches based on their TreeMaker-representation.
*
* The patmat translation doesn't rely on this, so it could be disabled in principle.
- *
- * TODO: split out match analysis
+ * - well, not quite: the backend crashes if we emit duplicates in switches (e.g. SI-7290)
*/
+// TODO: split out match analysis
trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
import PatternMatchingStats._
import global.{Tree, Type, Symbol, NoSymbol, CaseDef, atPos,
@@ -457,9 +457,9 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
case _ => t
}
// SI-7290 Discard duplicate alternatives that would crash the backend
- def distinctAlts = distinctBy(switchableAlts)(extractConst)
+ val distinctAlts = distinctBy(switchableAlts)(extractConst)
if (distinctAlts.size < switchableAlts.size) {
- val duplicated = switchableAlts.groupBy(extractConst).flatMap(_._2.drop(1))
+ val duplicated = switchableAlts.groupBy(extractConst).flatMap(_._2.drop(1).take(1)) // report the first duplicated
global.currentUnit.warning(pos, s"Pattern contains duplicate alternatives: ${duplicated.mkString(", ")}")
}
CaseDef(Alternative(distinctAlts), guard, body)