From 8d82ebbe360a33883d4904918321780d9d349928 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 31 Oct 2006 10:13:43 +0000 Subject: Fixed bug 694 --- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 20 ++++++++++++++++---- .../scala/tools/nsc/typechecker/Typers.scala | 5 +++-- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') 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) -- cgit v1.2.3