From a703d69eab35c7008ccf18836101fbc5c592b376 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 20 Dec 2007 16:35:10 +0000 Subject: fixed build problem on ibm's VM --- src/compiler/scala/tools/nsc/symtab/Types.scala | 32 ++++++++++++++++++++-- .../nsc/symtab/classfile/ClassfileParser.scala | 5 +--- .../scala/tools/nsc/typechecker/Infer.scala | 2 ++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index e16e1be2d6..a773fcd79e 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -2464,6 +2464,32 @@ A type's typeSymbol should never be inspected directly. owner.newAbstractType(owner.pos, newTypeName(freshTypeName()+suffix)).setFlag(EXISTENTIAL) ).setInfo(bounds) + def typeParamsToExistentials(clazz: Symbol, tparams: List[Symbol]): List[Symbol] = { + val eparams = for (tparam <- tparams) yield { + makeExistential("", clazz, tparam.info.bounds) + } + for (val tparam <- eparams) tparam setInfo tparam.info.substSym(tparams, eparams) + eparams + } + + /** The raw to existential map converts a ``raw type'' to an existential type. + * It is necessary because we might have read a raw type of a + * parameterized Java class from a class file. At the time we read the type + * the corresponding class file might still not be read, so we do not + * know what the type parameters of the type are. Therefore + * the conversion of raw types to existential types might not have taken place + * in ClassFileparser.sigToType (where it is usually done) + */ + object rawToExistential extends TypeMap { + def apply(tp: Type): Type = tp match { + case TypeRef(pre, sym, List()) if (sym.hasFlag(JAVA) && !sym.typeParams.isEmpty) => + val eparams = typeParamsToExistentials(sym, sym.typeParams) + existentialAbstraction(eparams, TypeRef(pre, sym, eparams map (_.tpe))) + case _ => + mapOver(tp) + } + } + /** A map to compute the asSeenFrom method */ class AsSeenFromMap(pre: Type, clazz: Symbol) extends TypeMap { override val dropNonConstraintAnnotations = true @@ -2579,13 +2605,15 @@ A type's typeSymbol should never be inspected directly. pre.baseType(symclazz) match { case TypeRef(_, basesym, baseargs) => //Console.println("instantiating " + sym + " from " + basesym + " with " + basesym.typeParams + " and " + baseargs+", pre = "+pre+", symclazz = "+symclazz);//DEBUG - if (basesym.typeParams.length != baseargs.length) + if (basesym.typeParams.length == baseargs.length) { + instParam(basesym.typeParams, baseargs) + } else { throw new TypeError( "something is wrong (wrong class file?): "+basesym+ " with type parameters "+ basesym.typeParams.map(_.name).mkString("[",",","]")+ " gets applied to arguments "+baseargs.mkString("[",",","]")+", phase = "+phase) - instParam(basesym.typeParams, baseargs); + } case ExistentialType(tparams, qtpe) => capturedParams = capturedParams union tparams toInstance(qtpe, clazz) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 73b81107ee..987411c6d8 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -503,10 +503,7 @@ abstract class ClassfileParser { else if (classSym.isMonomorphicType) classSym.tpe else { // raw type - existentially quantify all type parameters - val eparams = for (tparam <- classSym.unsafeTypeParams) yield { - val newSym = clazz.newAbstractType(NoPosition, fresh.newName) - newSym.setInfo(tparam.info.bounds) setFlag EXISTENTIAL - } + val eparams = typeParamsToExistentials(classSym, classSym.unsafeTypeParams) val t = appliedType(classSym.typeConstructor, eparams.map(_.tpe)) val res = existentialAbstraction(eparams, t) if (settings.debug.value && settings.verbose.value) println("raw type " + classSym + " -> " + res) diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index f3d0208ab5..8571148479 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -328,6 +328,8 @@ trait Infer { else " contains a "+ex.msg)) ErrorType } + if (sym1.isTerm && (sym1 hasFlag JAVA)) + owntype = rawToExistential(owntype) if (pre.isInstanceOf[SuperType]) owntype = owntype.substSuper(pre, site.symbol.thisType) tree setSymbol sym1 setType owntype -- cgit v1.2.3