summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-08-03 21:17:25 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-08-03 21:17:25 -0700
commitb23a0df06d4479e4e29aa2ce629f4704f29ab5a0 (patch)
tree781d7e24db6ff030a83e9e2ddffc1607890fa40a /src/compiler
parentf26ac6e643a54379c7bfd992356f88f6202b6081 (diff)
parent75eb8a49842075bcaa2878b262443b48aafec2ab (diff)
downloadscala-b23a0df06d4479e4e29aa2ce629f4704f29ab5a0.tar.gz
scala-b23a0df06d4479e4e29aa2ce629f4704f29ab5a0.tar.bz2
scala-b23a0df06d4479e4e29aa2ce629f4704f29ab5a0.zip
Merge pull request #982 from adriaanm/ticket-wolfcry
SI-5930 SI-5897 reduce redundant warnings in matches, fix flags usage
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala6
-rw-r--r--src/compiler/scala/tools/nsc/transform/TailCalls.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala15
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala6
5 files changed, 20 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index be5909a67f..144fb0d5ec 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -72,8 +72,6 @@ abstract class TreeGen extends reflect.internal.TreeGen with TreeDSL {
Annotated(Ident(nme.synthSwitch), expr)
}
- def hasSynthCaseSymbol(t: Tree) = (t.symbol ne null) && (t.symbol hasFlag (CASE | SYNTHETIC))
-
// TODO: would be so much nicer if we would know during match-translation (i.e., type checking)
// whether we should emit missingCase-style apply (and isDefinedAt), instead of transforming trees post-factum
class MatchMatcher {
@@ -94,13 +92,13 @@ abstract class TreeGen extends reflect.internal.TreeGen with TreeDSL {
case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), List(scrut)), List(matcher)) if opt.virtPatmat => // println("virt match: "+ (tgt, targs, scrut, matcher) + "for:\n"+ matchExpr )
caseVirtualizedMatch(matchExpr, tgt, targs, scrut, matcher)
// optimized version of virtpatmat
- case Block(stats, matchEndDef) if opt.virtPatmat && (stats forall hasSynthCaseSymbol) =>
+ case Block(stats, matchEndDef) if opt.virtPatmat && (stats forall treeInfo.hasSynthCaseSymbol) =>
// the assumption is once we encounter a case, the remainder of the block will consist of cases
// the prologue may be empty, usually it is the valdef that stores the scrut
val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, identity)
// optimized version of virtpatmat
- case Block(outerStats, orig@Block(stats, matchEndDef)) if opt.virtPatmat && (stats forall hasSynthCaseSymbol) =>
+ case Block(outerStats, orig@Block(stats, matchEndDef)) if opt.virtPatmat && (stats forall treeInfo.hasSynthCaseSymbol) =>
val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, m => copyBlock(matchExpr, outerStats, m))
case other =>
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
index 492273dfdc..770aa8b7ac 100644
--- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala
+++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
@@ -36,7 +36,7 @@ abstract class TailCalls extends Transform {
}
}
- import gen.hasSynthCaseSymbol
+ import treeInfo.hasSynthCaseSymbol
/**
* A Tail Call Transformer
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index cf5c7265ad..a4457936c8 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -113,7 +113,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
import definitions._
import analyzer._ //Typer
- val SYNTH_CASE = Flags.CASE | SYNTHETIC
case class DefaultOverrideMatchAttachment(default: Tree)
@@ -241,7 +240,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// append the default to the list of cases and suppress the unreachable case error that may arise (once we detect that...)
val matchFailGenOverride = match_.attachments.get[DefaultOverrideMatchAttachment].map{case DefaultOverrideMatchAttachment(default) => ((scrut: Tree) => default)}
- val selectorSym = freshSym(selector.pos, pureType(selectorTp)) setFlag SYNTH_CASE
+ val selectorSym = freshSym(selector.pos, pureType(selectorTp)) setFlag treeInfo.SYNTH_CASE_FLAGS
+
// pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala with -Xexperimental
val combined = combineCases(selector, selectorSym, cases map translateCase(selectorSym, pt), pt, matchOwner, matchFailGenOverride)
@@ -1317,6 +1317,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def freshSym(pos: Position, tp: Type = NoType, prefix: String = "x") =
NoSymbol.newTermSymbol(freshName(prefix), pos) setInfo tp
+ def newSynthCaseLabel(name: String) =
+ NoSymbol.newLabel(freshName(name), NoPosition) setFlag treeInfo.SYNTH_CASE_FLAGS
+
// codegen relevant to the structure of the translation (how extractors are combined)
trait AbsCodegen {
def matcher(scrut: Tree, scrutSym: Symbol, restpe: Type)(cases: List[Casegen => Tree], matchFailGen: Option[Tree => Tree]): Tree
@@ -1487,7 +1490,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
case object FalseCond extends Cond {override def toString = "F"}
case class AndCond(a: Cond, b: Cond) extends Cond {override def toString = a +"/\\"+ b}
- case class OrCond(a: Cond, b: Cond) extends Cond {override def toString = "("+a+") \\/ ("+ b +")"}
+ case class OrCond(a: Cond, b: Cond) extends Cond {override def toString = "("+a+") \\/ ("+ b +")"}
object EqualityCond {
private val uniques = new collection.mutable.HashMap[(Tree, Tree), EqualityCond]
@@ -3109,7 +3112,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
}
}
- private val defaultLabel: Symbol = NoSymbol.newLabel(freshName("default"), NoPosition) setFlag SYNTH_CASE
+ private val defaultLabel: Symbol = newSynthCaseLabel("default")
/** Collapse guarded cases that switch on the same constant (the last case may be unguarded).
*
@@ -3477,11 +3480,11 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
* if keepGoing is false, the result Some(x) of the naive translation is encoded as matchRes == x
*/
def matcher(scrut: Tree, scrutSym: Symbol, restpe: Type)(cases: List[Casegen => Tree], matchFailGen: Option[Tree => Tree]): Tree = {
- val matchEnd = NoSymbol.newLabel(freshName("matchEnd"), NoPosition) setFlag SYNTH_CASE
+ val matchEnd = newSynthCaseLabel("matchEnd")
val matchRes = NoSymbol.newValueParameter(newTermName("x"), NoPosition, SYNTHETIC) setInfo restpe.withoutAnnotations //
matchEnd setInfo MethodType(List(matchRes), restpe)
- def newCaseSym = NoSymbol.newLabel(freshName("case"), NoPosition) setInfo MethodType(Nil, restpe) setFlag SYNTH_CASE
+ def newCaseSym = newSynthCaseLabel("case") setInfo MethodType(Nil, restpe)
var _currCase = newCaseSym
val caseDefs = cases map { (mkCase: Casegen => Tree) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 9501998152..29ed8e6013 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1541,7 +1541,8 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
transform(qual)
case Apply(fn, args) =>
- checkSensible(tree.pos, fn, args)
+ // sensicality should be subsumed by the unreachability/exhaustivity/irrefutability analyses in the pattern matcher
+ if (!inPattern) checkSensible(tree.pos, fn, args)
currentApplication = tree
tree
}
@@ -1718,7 +1719,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
val pat1 = transform(pat)
inPattern = false
treeCopy.CaseDef(tree, pat1, transform(guard), transform(body))
- case LabelDef(_, _, _) if gen.hasSynthCaseSymbol(result) =>
+ case LabelDef(_, _, _) if treeInfo.hasSynthCaseSymbol(result) =>
val old = inPattern
inPattern = true
val res = deriveLabelDef(result)(transform)
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
index 38c2c5f719..74c51ece9f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
@@ -401,7 +401,11 @@ trait TypeDiagnostics {
object checkDead {
private var expr: Symbol = NoSymbol
- private def exprOK = expr != Object_synchronized
+
+ private def exprOK =
+ (expr != Object_synchronized) &&
+ !(expr.isLabel && treeInfo.isSynthCaseSymbol(expr)) // it's okay to jump to matchEnd (or another case) with an argument of type nothing
+
private def treeOK(tree: Tree) = tree.tpe != null && tree.tpe.typeSymbol == NothingClass
def updateExpr(fn: Tree) = {