diff options
author | Martin Odersky <odersky@gmail.com> | 2006-10-07 14:24:21 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-10-07 14:24:21 +0000 |
commit | 24284feee5c3dfebbbd8dc317b30a657cf9fe42c (patch) | |
tree | 5ae1fe9e3770ce1f11b99842d6a0fc4fdc613cdc /src | |
parent | fa37aa44cc4219f4cf5e7f85817be501104cf2dd (diff) | |
download | scala-24284feee5c3dfebbbd8dc317b30a657cf9fe42c.tar.gz scala-24284feee5c3dfebbbd8dc317b30a657cf9fe42c.tar.bz2 scala-24284feee5c3dfebbbd8dc317b30a657cf9fe42c.zip |
towards getting wildcard types
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 27 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 26 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 |
4 files changed, 18 insertions, 40 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index a8b64575cb..a5667ece19 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -570,7 +570,8 @@ trait Trees requires Global { extends TypTree { override def symbol: Symbol = tpt.symbol override def symbol_=(sym: Symbol): unit = { tpt.symbol = sym } - } + +} /* A standard pattern match case EmptyTree => diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 379a157b44..56f332689d 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -647,7 +647,8 @@ trait Types requires SymbolTable { override def bounds: TypeBounds = this def containsType(that: Type) = that <:< this || lo <:< that && that <:< hi; // override def isNullable: boolean = AllRefClass.tpe <:< lo; - override def toString() = ">: " + lo + " <: " + hi + override def toString = "_ "+boundsString + def boundsString = ">: "+lo+" <: "+ hi } /** A common base class for intersection types and class types @@ -1335,7 +1336,13 @@ trait Types requires SymbolTable { else SuperType(thistp1, supertp1) case TypeRef(pre, sym, args) => val pre1 = this(pre) - val args1 = List.mapConserve(args)(this) + //val args1 = List.mapConserve(args)(this) + val args1 = if (args.isEmpty) args + else { + val tparams = sym.typeParams + if (tparams.isEmpty) args + else mapOverArgs(args, tparams) + } if ((pre1 eq pre) && (args1 eq args)) tp else typeRef(pre1, sym, args1, variance) case TypeBounds(lo, hi) => @@ -1395,7 +1402,7 @@ trait Types requires SymbolTable { } def mapOverArgs(args: List[Type], tparams: List[Symbol]): List[Type] = args match { - case List() => List() + case List() => args case arg :: args0 => val v = variance if (tparams.head.isContravariant) variance = -variance @@ -2326,20 +2333,12 @@ trait Types requires SymbolTable { if (tparam.variance == variance) lub(as) else if (tparam.variance == -variance) glb(as) else NoType)); - try { - if (args contains NoType) None - else Some(typeRef(pre, sym, args, variance)) - } catch { - case ex: MalformedType => None - } + if (args contains NoType) None + else Some(typeRef(pre, sym, args, variance)) case SingleType(_, sym) :: rest => val pres = tps map (.prefix) val pre = if (variance == 1) lub(pres) else glb(pres) - try { - Some(singleType(pre, sym, variance)) - } catch { - case ex: MalformedType => None - } + Some(singleType(pre, sym, variance)) } /** Make symbol <code>sym</code> a member of scope <code>tp.decls</code> diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 9c4b1d3647..6a10220cc0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -321,12 +321,6 @@ trait Infer requires Analyzer { (tp1 <:< pt) || isCoercible(tp, pt) } - def isCompatible(pre: Type, sym: Symbol, pt: Type): boolean = try { - isCompatible(pre.memberType(sym), pt) - } catch { - case ex: MalformedType => false - } - def isWeaklyCompatible(tp: Type, pt: Type): boolean = pt.symbol == UnitClass || isCompatible(tp, pt) @@ -505,22 +499,6 @@ trait Infer requires Analyzer { false } - /** Is there an instantiation of free type variables <code>undetparams</code> - * such that function type <code>ftpe</code> is applicable to - * <code>argtpes</code> and its result conform to <code>pt</code>? - * - * @param undetparams ... - * @param ftpe ... - * @param argtpes ... - * @param pt ... - * @return ... - */ - def isApplicable(undetparams: List[Symbol], pre: Type, sym: Symbol, argtpes: List[Type], pt: Type): boolean = try { - isApplicable(undetparams, pre.memberType(sym), argtpes, pt) - } catch { - case ex: MalformedType => false - } - /** Does type <code>ftpe1</code> specialize type <code>ftpe2</code> * when both are alternatives in an overloaded function? * @@ -786,7 +764,7 @@ trait Infer requires Analyzer { */ def inferExprAlternative(tree: Tree, pt: Type): unit = tree.tpe match { case OverloadedType(pre, alts) => tryTwice { - var alts1 = alts filter (alt => isCompatible(pre, alt, pt)) + var alts1 = alts filter (alt => isCompatible(pre.memberType(alt), pt)) if (alts1.isEmpty) alts1 = alts def improves(sym1: Symbol, sym2: Symbol): boolean = sym2 == NoSymbol || @@ -833,7 +811,7 @@ trait Infer requires Analyzer { def inferMethodAlternative(tree: Tree, undetparams: List[Symbol], argtpes: List[Type], pt: Type): unit = tree.tpe match { case OverloadedType(pre, alts) => tryTwice { if (settings.debug.value) log("infer method alt " + tree.symbol + " with alternatives " + (alts map pre.memberType) + ", argtpes = " + argtpes + ", pt = " + pt) - val applicable = alts filter (alt => isApplicable(undetparams, pre, alt, argtpes, pt)) + val applicable = alts filter (alt => isApplicable(undetparams, pre.memberType(alt), argtpes, pt)) def improves(sym1: Symbol, sym2: Symbol) = ( sym2 == NoSymbol || sym2.isError || ((sym1.owner isSubClass sym2.owner) && diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 7a452479d6..d8c35441b2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1127,7 +1127,7 @@ trait Typers requires Analyzer { // preadapt symbol to number of arguments given val argtypes = args map (arg => AllClass.tpe) val pre = fun.symbol.tpe.prefix - val sym = fun.symbol filter (alt => isApplicable(context.undetparams, pre, alt, argtypes, pt)) + val sym = fun.symbol filter (alt => isApplicable(context.undetparams, pre.memberType(alt), argtypes, pt)) if (sym != NoSymbol) fun = adapt(fun setSymbol sym setType pre.memberType(sym), funMode(mode), WildcardType) } |