From b186613b3e9e65197d855f0924c211844d91be68 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 21 Dec 2007 14:20:50 +0000 Subject: changed how wildcards are displayed --- src/compiler/scala/tools/nsc/symtab/Types.scala | 20 ++++++++++++-------- .../tools/nsc/symtab/classfile/ClassfileParser.scala | 7 ++++--- test/files/neg/bug1010.check | 2 +- test/files/neg/bug608.check | 2 +- test/files/neg/sabin2.check | 2 +- test/files/neg/t0209.check | 2 +- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index a773fcd79e..0ac490f64e 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -2459,14 +2459,18 @@ A type's typeSymbol should never be inspected directly. * @param owner The owner of the variable * @param bounds The variable's bounds */ - def makeExistential(suffix: String, owner: Symbol, bounds: TypeBounds): Symbol = + def makeExistential(name: String, owner: Symbol, bounds: TypeBounds): Symbol = recycle( - owner.newAbstractType(owner.pos, newTypeName(freshTypeName()+suffix)).setFlag(EXISTENTIAL) + owner.newAbstractType(owner.pos, newTypeName(name)).setFlag(EXISTENTIAL) ).setInfo(bounds) + /** Make an existential variable with a fresh name. */ + def makeFreshExistential(suffix: String, owner: Symbol, bounds: TypeBounds): Symbol = + makeExistential(freshName()+suffix, owner, bounds) + def typeParamsToExistentials(clazz: Symbol, tparams: List[Symbol]): List[Symbol] = { - val eparams = for (tparam <- tparams) yield { - makeExistential("", clazz, tparam.info.bounds) + val eparams = for ((tparam, i) <- tparams.zipWithIndex) yield { + makeExistential("?"+i, clazz, tparam.info.bounds) } for (val tparam <- eparams) tparam setInfo tparam.info.substSym(tparams, eparams) eparams @@ -2530,7 +2534,7 @@ A type's typeSymbol should never be inspected directly. def stabilize(pre: Type, clazz: Symbol): Type = { capturedPre get clazz match { case None => - val qvar = makeExistential(".type", clazz, + val qvar = makeFreshExistential(".type", clazz, mkTypeBounds(AllClass.tpe, intersectionType(List(pre, SingletonClass.tpe)))) capturedPre += (clazz -> qvar) capturedParams = qvar :: capturedParams @@ -3118,9 +3122,9 @@ A type's typeSymbol should never be inspected directly. import Math.max private var nextid = 0 - private def freshTypeName() = { + private def freshName() = { nextid += 1 - newTypeName("_"+nextid) + "_"+nextid } /** The maximum depth of all types in the closures of each of the types `tps' */ @@ -4123,7 +4127,7 @@ A type's typeSymbol should never be inspected directly. if (l <:< g) l else { val owner = commonOwner(as) - val qvar = makeExistential("", commonOwner(as), mkTypeBounds(g, l)) + val qvar = makeFreshExistential("", commonOwner(as), mkTypeBounds(g, l)) capturedParams += qvar qvar.tpe } diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 987411c6d8..7b0aa57bde 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -12,7 +12,7 @@ import java.lang.Integer.toHexString import scala.collection.immutable.{Map, ListMap} import scala.collection.mutable.{ListBuffer, ArrayBuffer} import scala.tools.nsc.io.AbstractFile -import scala.tools.nsc.util.{FreshNameCreator, Position, NoPosition} +import scala.tools.nsc.util.{Position, NoPosition} /** This abstract class implements a class file parser. @@ -39,7 +39,6 @@ abstract class ClassfileParser { protected var hasMeta: Boolean = _ // does class file contain jaco meta attribute?s protected var busy: Boolean = false // lock to detect recursive reads protected var classTParams = Map[Name,Symbol]() - protected val fresh = new FreshNameCreator.Default private object metaParser extends MetaParser { val global: ClassfileParser.this.global.type = ClassfileParser.this.global @@ -476,6 +475,7 @@ abstract class ClassfileParser { val tpe: Type = if (sig(index) == '<') { accept('<') val xs = new ListBuffer[Type]() + var i = 0 while (sig(index) != '>') { sig(index) match { case variance @ ('+' | '-' | '*') => @@ -488,9 +488,10 @@ abstract class ClassfileParser { case '*' => mkTypeBounds(definitions.AllClass.tpe, definitions.AnyClass.tpe) } - val newtparam = makeExistential("", sym, bounds) + val newtparam = makeExistential("?"+i, sym, bounds) existentials += newtparam xs += newtparam.tpe + i += 1 case _ => xs += sig2type(tparams) } diff --git a/test/files/neg/bug1010.check b/test/files/neg/bug1010.check index 35390aa88a..3cf9738eaa 100644 --- a/test/files/neg/bug1010.check +++ b/test/files/neg/bug1010.check @@ -1,6 +1,6 @@ bug1010.scala:14: error: type mismatch; found : MailBox#Message - required: _16.in.Message where val _16: Actor + required: _3.in.Message where val _3: Actor unstable.send(msg) // in.Message becomes unstable.Message, but that's ok since Message is a concrete type member ^ one error found diff --git a/test/files/neg/bug608.check b/test/files/neg/bug608.check index e0acf6fa0f..8337c513ff 100644 --- a/test/files/neg/bug608.check +++ b/test/files/neg/bug608.check @@ -1,6 +1,6 @@ bug608.scala:16: error: type mismatch; found : (a) => a - required: (_14.a) => ? where val _14: hs{type s = hs; type a = ha} + required: (_1.a) => ? where val _1: hs{type s = hs; type a = ha} = g(f(x).bimap(id)) ^ one error found diff --git a/test/files/neg/sabin2.check b/test/files/neg/sabin2.check index 070b03a54b..92578bc23e 100644 --- a/test/files/neg/sabin2.check +++ b/test/files/neg/sabin2.check @@ -1,6 +1,6 @@ sabin2.scala:22: error: type mismatch; found : Test.Base#T - required: _20.T where val _20: Test.Base + required: _7.T where val _7: Test.Base a.set(b.get()) // Error ^ one error found diff --git a/test/files/neg/t0209.check b/test/files/neg/t0209.check index 19e06d10b9..38b911533f 100644 --- a/test/files/neg/t0209.check +++ b/test/files/neg/t0209.check @@ -1,6 +1,6 @@ t0209.scala:15: error: type mismatch; found : C - required: _14 where val _14: A + required: _1 where val _1: A (new B: A).f(new C) ^ one error found -- cgit v1.2.3