diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-03-27 08:13:24 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-03-27 08:16:41 +0100 |
commit | c3ad5af27df1b365873870827a6093f630881343 (patch) | |
tree | 6832b696164a8162cc7fe7b95d0acbba2e1b8dba | |
parent | 2e0be8323bdef5582a0f5af84b3de83fcc338be4 (diff) | |
download | scala-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
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/patmat/MatchOptimization.scala | 8 | ||||
-rw-r--r-- | test/files/neg/t7290.check | 2 |
2 files changed, 5 insertions, 5 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) diff --git a/test/files/neg/t7290.check b/test/files/neg/t7290.check index 15f30e8bce..85bedbac95 100644 --- a/test/files/neg/t7290.check +++ b/test/files/neg/t7290.check @@ -1,7 +1,7 @@ t7290.scala:4: error: Pattern contains duplicate alternatives: 0 case 0 | 0 => 0 ^ -t7290.scala:5: error: Pattern contains duplicate alternatives: 2, 2, 2, 3 +t7290.scala:5: error: Pattern contains duplicate alternatives: 2, 3 case 2 | 2 | 2 | 3 | 2 | 3 => 0 ^ t7290.scala:6: error: Pattern contains duplicate alternatives: 4 |