summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala20
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala5
-rwxr-xr-xtest/files/pos/bug694.scala10
3 files changed, 29 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 476fefac7d..680cc8cf91 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -745,13 +745,13 @@ trait Infer requires Analyzer {
val ptvars = ptparams map freshVar
val pt1 = pt.subst(ptparams, ptvars)
if (isPopulated(restpe, pt1)) {
- ptvars foreach instantiateTypeVar(false)
+ ptvars foreach instantiateTypeVar
} else { if (settings.debug.value) System.out.println("no instance: "); instError }
} else { if (settings.debug.value) System.out.println("not a subtype " + restpe.subst(undetparams, tvars) + " of " + ptWithWildcards); instError }
} else { if (settings.debug.value) System.out.println("not fuly defined: " + pt); instError }
}
- def instantiateTypeVar(aliasOK: boolean)(tvar: TypeVar) = {
+ def instantiateTypeVar(tvar: TypeVar) = {
val tparam = tvar.origin.symbol
if (false &&
tvar.constr.inst != NoType &&
@@ -851,13 +851,25 @@ trait Infer requires Analyzer {
error(tpt.pos, "pattern type is incompatibe with expected type"+foundReqMsg(tpt.tpe, pt))
return tpt.tpe
}
- ptvars foreach instantiateTypeVar(false)
+ ptvars foreach instantiateTypeVar
}
- tvars foreach instantiateTypeVar(true)
+ tvars foreach instantiateTypeVar
}
intersect(pt, tpt.tpe)
}
+ def inferModulePattern(pat: Tree, pt: Type) =
+ if (!(pat.tpe <:< pt)) {
+ val ptparams = freeTypeParamsOfTerms.collect(pt)
+ if (settings.debug.value) log("free type params (2) = " + ptparams)
+ val ptvars = ptparams map freshVar
+ val pt1 = pt.subst(ptparams, ptvars)
+ if (pat.tpe <:< pt1)
+ ptvars foreach instantiateTypeVar
+ else
+ error(pat.pos, "pattern type is incompatibe with expected type"+foundReqMsg(pat.tpe, pt))
+ }
+
object toOrigin extends TypeMap {
def apply(tp: Type): Type = tp match {
case TypeVar(origin, _) => origin
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 6b76f71b6f..756587fbba 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -596,10 +596,11 @@ trait Typers requires Analyzer {
typed(atPos(tree.pos)(Select(qual, nme.apply)), mode, pt)
} else if (!context.undetparams.isEmpty && (mode & POLYmode) == 0) { // (9)
instantiate(tree, mode, pt)
- } else if ((mode & PATTERNmode) != 0) {
- tree
} else if (tree.tpe <:< pt) {
tree
+ } else if ((mode & PATTERNmode) != 0) {
+ if (tree.symbol.isModule) inferModulePattern(tree, pt)
+ tree
} else {
val tree1 = constfold(tree, pt) // (10) (11)
if (tree1.tpe <:< pt) adapt(tree1, mode, pt)
diff --git a/test/files/pos/bug694.scala b/test/files/pos/bug694.scala
new file mode 100755
index 0000000000..ebabc658ce
--- /dev/null
+++ b/test/files/pos/bug694.scala
@@ -0,0 +1,10 @@
+object test3 {
+ trait Type[T];
+ case object IntType extends Type[Int];
+ case object StringType extends Type[String];
+
+ def f[T](t : Type[T]) : T = t match {
+ case IntType => 10;
+ case StringType => "hello";
+ }
+}