summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-10-31 10:13:43 +0000
committerMartin Odersky <odersky@gmail.com>2006-10-31 10:13:43 +0000
commit8d82ebbe360a33883d4904918321780d9d349928 (patch)
tree85216b15cb58100052cc60f5069e7d60abd7d657 /src
parente02fed8e7df8aebe1ee96b3dc23b805c1171afd2 (diff)
downloadscala-8d82ebbe360a33883d4904918321780d9d349928.tar.gz
scala-8d82ebbe360a33883d4904918321780d9d349928.tar.bz2
scala-8d82ebbe360a33883d4904918321780d9d349928.zip
Fixed bug 694
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala20
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala5
2 files changed, 19 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)