summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala8
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternBindings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/matching/Patterns.scala27
3 files changed, 19 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index d06ef94432..a5602dbeab 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -248,7 +248,7 @@ trait ParallelMatching extends ast.TreeDSL
def tail = ps.tail
def size = ps.length
- def headType = head.matchingType
+ def headType = head.typeToMatch
def isCaseHead = head.isCaseClass
private val dummyCount = if (isCaseHead) headType.typeSymbol.caseFieldAccessors.length else 0
def dummies = emptyPatterns(dummyCount)
@@ -664,7 +664,7 @@ trait ParallelMatching extends ast.TreeDSL
def pMatchesS = matches(p, s)
def alts[T](yes: T, no: T): T = if (p =:= s) yes else no
- def isObjectTest = pattern.isObject && (p =:= pattern.matchingType)
+ def isObjectTest = pattern.isObject && (p =:= pattern.typeToMatch)
lazy val dummy = (j, pats.dummies)
lazy val pass = (j, pattern)
@@ -1049,6 +1049,10 @@ trait ParallelMatching extends ast.TreeDSL
assert((tpe ne NoType) && (scrutTree.tpe ne NoType))
def useEqTest = tpe.termSymbol.isModule || (tpe.prefix eq NoPrefix)
+ // case SingleType(_, _) | ThisType(_) | SuperType(_, _) =>
+ // val cmpOp = if (targ.tpe <:< AnyValClass.tpe) Any_equals else Object_eq
+ // Apply(Select(qual, cmpOp), List(gen.mkAttributedQualifier(targ.tpe)))
+
typer typed (tpe match {
case ct: ConstantType => ct.value match {
case v @ Constant(null) if scrutTree.tpe.isAnyRef => scrutTree ANY_EQ NULL
diff --git a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala
index 92174b0018..c85ecfe721 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala
@@ -89,7 +89,7 @@ trait PatternBindings extends ast.TreeDSL
// Like rebindToEqualsCheck, but subtly different. Not trying to be
// mysterious -- I haven't sorted it all out yet.
def rebindToObjectCheck(): Pattern = {
- val sType = mkSingleton
+ val sType = typeToMatch
rebindToType(mkEqualsRef(sType), sType)
}
diff --git a/src/compiler/scala/tools/nsc/matching/Patterns.scala b/src/compiler/scala/tools/nsc/matching/Patterns.scala
index b346aec329..17f69ea2dd 100644
--- a/src/compiler/scala/tools/nsc/matching/Patterns.scala
+++ b/src/compiler/scala/tools/nsc/matching/Patterns.scala
@@ -77,16 +77,16 @@ trait Patterns extends ast.TreeDSL {
require (!isVarPattern(fn) && args.isEmpty)
val ident @ Ident(name) = fn
+ override def typeToMatch = Pattern(ident).equalsCheck
override def simplify(testVar: Symbol) = this.rebindToObjectCheck()
- override def mkSingleton = Pattern(ident).equalsCheck
override def toString() = "Id(%s)".format(name)
}
// 8.1.4 (b)
case class ApplySelectPattern(tree: Apply) extends ApplyPattern with SelectPattern {
val Apply(select: Select, _) = tree
+ override def typeToMatch = mkSingletonFromQualifier
override def simplify(testVar: Symbol) = this.rebindToObjectCheck()
- override def mkSingleton = mkSingletonFromQualifier
override def toString() = "SelectApply(%s)".format(name)
}
// 8.1.4 (c)
@@ -98,7 +98,7 @@ trait Patterns extends ast.TreeDSL {
case class ObjectPattern(tree: Apply) extends ApplyPattern { // NamePattern?
require(!fn.isType && isModule)
- override def matchingType = mkSingleton
+ override def typeToMatch = tpe.narrow
override def simplify(testVar: Symbol) = this.rebindToObjectCheck()
override def toString() = "Object(%s)".format(fn)
}
@@ -136,14 +136,14 @@ trait Patterns extends ast.TreeDSL {
private val MethodType(List(arg, _*), _) = fn.tpe
private def uaTyped = Typed(tree, TypeTree(arg.tpe)) setType arg.tpe
- override def matchingType = arg.tpe
+ override def typeToMatch = arg.tpe
// can fix #1697 here?
override def simplify(testVar: Symbol) =
if (testVar.tpe <:< arg.tpe) this
else this rebindTo uaTyped
- override def toString() = "Unapply(f: %s => %s)".format(matchingType, fn.tpe.resultType)
+ override def toString() = "Unapply(f: %s => %s)".format(typeToMatch, fn.tpe.resultType)
}
// 8.1.8 (unapplySeq calls)
@@ -370,7 +370,7 @@ trait Patterns extends ast.TreeDSL {
protected def mkSingletonFromQualifier = {
def pType = qualifier match {
case _: Apply => PseudoType(tree)
- case _ => singleType(Pattern(qualifier).mkSingleton, sym)
+ case _ => singleType(Pattern(qualifier).typeToMatch, sym)
}
qualifier.tpe match {
case t: ThisType => singleType(t, sym) // this.X
@@ -381,8 +381,8 @@ trait Patterns extends ast.TreeDSL {
sealed trait NamePattern extends Pattern {
def name: Name
+ override def typeToMatch = tpe.narrow
override def simplify(testVar: Symbol) = this.rebindToEqualsCheck()
- override def matchingType = mkSingleton
}
// trait SimplePattern extends Pattern {
@@ -424,7 +424,7 @@ trait Patterns extends ast.TreeDSL {
def isDefault = false
// what type must a scrutinee have to match this pattern?
- def matchingType = tpe
+ def typeToMatch = tpe
// the subpatterns for this pattern (at the moment, that means constructor arguments)
def subpatterns(pm: MatchMatrix#PatternMatch): List[Pattern] = pm.dummies
@@ -445,13 +445,10 @@ trait Patterns extends ast.TreeDSL {
}
def equalsCheck =
- if (sym.isValue) singleType(NoPrefix, sym)
- else mkSingleton
-
- def mkSingleton = tpe match {
- case st: SingleType => st
- case _ => singleType(prefix, sym)
- }
+ tracing("equalsCheck",
+ if (sym.isValue) singleType(NoPrefix, sym)
+ else tpe.narrow
+ )
final def isAlternative = cond(tree) { case Alternative(_) => true }