summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-08-11 17:54:31 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-08-11 17:54:31 -0700
commit1aa578b5ac624639c20a51578521ccc630ee4816 (patch)
tree2faf948ab1ff5ef8363f35122da2f2fbc50c98c2 /src
parent8cabda828541942016bb2ab08cc6e68716f43d7b (diff)
parent88c9a3cdf16a22a8e07091a7845d45f1ce6a0ff7 (diff)
downloadscala-1aa578b5ac624639c20a51578521ccc630ee4816.tar.gz
scala-1aa578b5ac624639c20a51578521ccc630ee4816.tar.bz2
scala-1aa578b5ac624639c20a51578521ccc630ee4816.zip
Merge pull request #1120 from paulp/ticket-6184-revised
Ticket 6184 revised
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index 08c78706fe..8dc2cb34d6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -2460,15 +2460,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// e.g., when we know some value must be of type T, can it still be of type S? (this is the positive formulation of what `excludes` on Const computes)
// since we're talking values, there must have been a class involved in creating it, so rephrase our types in terms of classes
// (At least conceptually: `true` is an instance of class `Boolean`)
- private def widenToClass(tp: Type) = {
- // getOrElse to err on the safe side -- all BTS should end in Any, right?
- val wideTp = tp.widen
- val clsTp =
- if (wideTp.typeSymbol.isClass) wideTp
- else wideTp.baseTypeSeq.toList.find(_.typeSymbol.isClass).getOrElse(AnyClass.tpe)
- // patmatDebug("Widening to class: "+ (tp, clsTp, tp.widen, tp.widen.baseTypeSeq, tp.widen.baseTypeSeq.toList.find(_.typeSymbol.isClass)))
- clsTp
- }
+ private def widenToClass(tp: Type): Type =
+ if (tp.typeSymbol.isClass) tp
+ else tp.baseType(tp.baseClasses.head)
object TypeConst extends TypeConstExtractor {
def apply(tp: Type) = {
@@ -2687,17 +2681,19 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// TODO: this is subject to the availability of TypeTags (since an abstract type with a type tag is checkable at run time)
def checkableType(tp: Type): Type = {
// TODO: this is extremely rough...
- object toCheckable extends TypeMap {
- def apply(tp: Type) = tp match {
- case TypeRef(pre, sym, a :: as) if sym ne ArrayClass =>
- // replace type args by existentials, since they can't be checked
- // TODO: when type tags are available, we will check -- when this is implemented, can we take that into account here?
- // TODO: don't reuse sym.typeParams, they have bounds (and those must not be considered)
- newExistentialType(sym.typeParams, sym.tpe).asSeenFrom(pre, sym.owner)
- case _ => mapOver(tp)
+ // replace type args by wildcards, since they can't be checked (don't use existentials: overkill)
+ // TODO: when type tags are available, we will check -- when this is implemented, can we take that into account here?
+ // similar to typer.infer.approximateAbstracts
+ object typeArgsToWildcardsExceptArray extends TypeMap {
+ def apply(tp: Type): Type = tp match {
+ case TypeRef(pre, sym, args) if args.nonEmpty && (sym ne ArrayClass) =>
+ TypeRef(pre, sym, args map (_ => WildcardType))
+ case _ =>
+ mapOver(tp)
}
}
- val res = toCheckable(tp)
+
+ val res = typeArgsToWildcardsExceptArray(tp)
patmatDebug("checkable "+(tp, res))
res
}