diff options
author | Dmitry Petrashko <dark@d-d.me> | 2016-05-27 10:57:34 +0200 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2016-05-27 10:57:34 +0200 |
commit | 3ee785afadbc57f53ccb9cb0d8a98d0eb395dde2 (patch) | |
tree | 5c5765e616a346849abb31456f66678a77b53b43 /src | |
parent | 4b35f6f96caea6586de0c4ab001b5429b44d754b (diff) | |
parent | 772f3d20fd3605d077abf28e80195f1dda343ee1 (diff) | |
download | dotty-3ee785afadbc57f53ccb9cb0d8a98d0eb395dde2.tar.gz dotty-3ee785afadbc57f53ccb9cb0d8a98d0eb395dde2.tar.bz2 dotty-3ee785afadbc57f53ccb9cb0d8a98d0eb395dde2.zip |
Merge pull request #1256 from felixmulder/topic/test-bcode
Add bytecode checking infrastructure
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Definitions.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/PatternMatcher.scala | 8 |
3 files changed, 8 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index bcc986755..5cb373cfd 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -486,6 +486,8 @@ class Definitions { def TASTYLongSignatureAnnot(implicit ctx: Context) = TASTYLongSignatureAnnotType.symbol.asClass lazy val TailrecAnnotType = ctx.requiredClassRef("scala.annotation.tailrec") def TailrecAnnot(implicit ctx: Context) = TailrecAnnotType.symbol.asClass + lazy val SwitchAnnotType = ctx.requiredClassRef("scala.annotation.switch") + def SwitchAnnot(implicit ctx: Context) = SwitchAnnotType.symbol.asClass lazy val ThrowsAnnotType = ctx.requiredClassRef("scala.throws") def ThrowsAnnot(implicit ctx: Context) = ThrowsAnnotType.symbol.asClass lazy val TransientAnnotType = ctx.requiredClassRef("scala.transient") diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 71ea6d2b3..cec6fd3b1 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -107,7 +107,7 @@ object Types { * It makes no sense for it to be an alias type because isRef would always * return false in that case. */ - def isRef(sym: Symbol)(implicit ctx: Context): Boolean = stripTypeVar match { + def isRef(sym: Symbol)(implicit ctx: Context): Boolean = stripAnnots.stripTypeVar match { case this1: TypeRef => this1.info match { // see comment in Namer#typeDefSig case TypeAlias(tp) => tp.isRef(sym) diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 64b85a51f..24d0e9ae0 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -306,12 +306,11 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans def emitSwitch(scrut: Tree, scrutSym: Symbol, cases: List[List[TreeMaker]], pt: Type, matchFailGenOverride: Option[Symbol => Tree], unchecked: Boolean): Option[Tree] = { // TODO Deal with guards? - def isSwitchableType(tpe: Type): Boolean = { + def isSwitchableType(tpe: Type): Boolean = (tpe isRef defn.IntClass) || (tpe isRef defn.ByteClass) || (tpe isRef defn.ShortClass) || (tpe isRef defn.CharClass) - } object IntEqualityTestTreeMaker { def unapply(treeMaker: EqualityTestTreeMaker): Option[Int] = treeMaker match { @@ -423,7 +422,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans Match(intScrut, newCases :+ defaultCase) } - if (isSwitchableType(scrut.tpe.widenDealias) && cases.forall(isSwitchCase)) { + val dealiased = scrut.tpe.widenDealias + if (isSwitchableType(dealiased) && cases.forall(isSwitchCase)) { val valuesToCases = cases.map(extractSwitchCase) val values = valuesToCases.map(_._1) if (values.tails.exists { tail => tail.nonEmpty && tail.tail.exists(doOverlap(_, tail.head)) }) { @@ -433,6 +433,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans Some(makeSwitch(valuesToCases)) } } else { + if (dealiased hasAnnotation defn.SwitchAnnot) + ctx.warning("failed to emit switch for `@switch` annotated match") None } } |