summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-06-21 10:36:06 +0000
committerMartin Odersky <odersky@gmail.com>2006-06-21 10:36:06 +0000
commit2933e3f3cce9221a1fbe76b434957f8affb54548 (patch)
treeafce1c862f9f24d3d456a31edd1c1b0c59b7663b /src
parentb444420b5b136e8f6e3439c100fbcc5236e0100b (diff)
downloadscala-2933e3f3cce9221a1fbe76b434957f8affb54548.tar.gz
scala-2933e3f3cce9221a1fbe76b434957f8affb54548.tar.bz2
scala-2933e3f3cce9221a1fbe76b434957f8affb54548.zip
Fixed test files after syntax change for closures.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala31
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala14
-rw-r--r--src/library/scala/Predef.scala8
4 files changed, 45 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index e6a94f4aca..e2f8e23b3f 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -504,6 +504,10 @@ trait Types requires SymbolTable {
// override def isNullable: boolean = true
}
+ case class BoundedWildcardType(override val bounds: TypeBounds) extends Type {
+ override def toString(): String = "?" + bounds
+ }
+
/** An object representing a non-existing type */
case object NoType extends Type {
override def isTrivial: boolean = true
@@ -1147,9 +1151,10 @@ trait Types requires SymbolTable {
/** A class expressing upper and lower bounds constraints
* for type variables, as well as their instantiations */
- class TypeConstraint {
- var lobounds: List[Type] = List()
- var hibounds: List[Type] = List()
+ class TypeConstraint(lo: List[Type], hi: List[Type]) {
+ def this() = this(List(), List())
+ var lobounds: List[Type] = lo
+ var hibounds: List[Type] = hi
var inst: Type = NoType
def instantiate(tp: Type): boolean =
@@ -1208,6 +1213,10 @@ trait Types requires SymbolTable {
val hi1 = this(hi)
if ((lo1 eq lo) && (hi1 eq hi)) tp
else TypeBounds(lo1, hi1)
+ case BoundedWildcardType(bounds) =>
+ val bounds1 = this(bounds)
+ if (bounds1 eq bounds) tp
+ else BoundedWildcardType(bounds1.asInstanceOf[TypeBounds])
case RefinedType(parents, decls) =>
val parents1 = List.mapConserve(parents)(this);
val decls1 = mapOver(decls);
@@ -1379,8 +1388,12 @@ trait Types requires SymbolTable {
* type variable */
object wildcardToTypeVarMap extends TypeMap {
def apply(tp: Type): Type = tp match {
- case WildcardType => TypeVar(tp, new TypeConstraint)
- case _ => mapOver(tp)
+ case WildcardType =>
+ TypeVar(tp, new TypeConstraint)
+ case BoundedWildcardType(bounds) =>
+ TypeVar(tp, new TypeConstraint(List(bounds.lo), List(bounds.hi)))
+ case _ =>
+ mapOver(tp)
}
}
@@ -1575,6 +1588,10 @@ trait Types requires SymbolTable {
res1 =:= res2.substSym(tparams2, tparams1))
case Pair(TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) =>
lo1 =:= lo2 && hi1 =:= hi2
+ case Pair(BoundedWildcardType(bounds), _) =>
+ bounds containsType tp2
+ case Pair(_, BoundedWildcardType(bounds)) =>
+ bounds containsType tp1
case Pair(TypeVar(_, constr1), _) =>
if (constr1.inst != NoType) constr1.inst =:= tp2
else constr1 instantiate (wildcardToTypeVarMap(tp2))
@@ -1664,6 +1681,10 @@ trait Types requires SymbolTable {
res1 <:< res2.substSym(tparams2, tparams1))
case Pair(TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) =>
lo2 <:< lo1 && hi1 <:< hi2
+ case Pair(BoundedWildcardType(bounds), _) =>
+ bounds.lo <:< tp2
+ case Pair(_, BoundedWildcardType(bounds)) =>
+ tp1 <:< bounds.hi
case Pair(_, TypeVar(_, constr2)) =>
if (constr2.inst != NoType) tp1 <:< constr2.inst
else { constr2.lobounds = tp1 :: constr2.lobounds; true }
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 64a0c72416..f85c5040e4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -362,6 +362,7 @@ trait Contexts requires Analyzer {
if (tpeCache == null) tpeCache = pre.memberType(sym)
tpeCache
}
+ override def toString = "ImplicitInfo("+name+","+pre+","+sym+")"
}
val NoImplicitInfo = new ImplicitInfo(null, null, null)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 82af6dbaad..3991798aa1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1163,8 +1163,10 @@ trait Typers requires Analyzer {
context.undetparams = undetparams
val args1 = tryTypedArgs(args map (arg => UnTyper.apply(arg)))
context.reportGeneralErrors = reportGeneralErrors
+ def templateArgType(arg: Tree) =
+ new BoundedWildcardType(TypeBounds(arg.tpe, AnyClass.tpe))
val qual1 = if (args1 == null || pt.isError) qual
- else adaptToMember(qual, name, MethodType(args1 map (.tpe), pt))
+ else adaptToMember(qual, name, MethodType(args1 map templateArgType, pt))
val tree1 = Apply(Select(qual1, name) setPos fun.pos, args map (arg => UnTyper.apply(arg))) setPos tree.pos
typed1(tree1, mode | SNDTRYmode, pt)
} finally {
@@ -1572,7 +1574,9 @@ trait Typers requires Analyzer {
fun1.isInstanceOf[Select] &&
!fun1.tpe.isInstanceOf[ImplicitMethodType] &&
(mode & (EXPRmode | SNDTRYmode)) == EXPRmode) tryTypedApply(fun1, args)
- else typedApply(fun1, args)
+ else {
+ typedApply(fun1, args)
+ }
}
case Super(qual, mix) =>
@@ -1785,7 +1789,7 @@ trait Typers requires Analyzer {
* @returns A typed tree if the implicit info can be made to conform to `pt', EmptyTree otherwise.
* @pre info.tpe does not contain an error
*/
- private def typedImplicit(pos: int, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree =
+ private def typedImplicit(pos: int, info: ImplicitInfo, pt: Type, isLocal: boolean): Tree = {
if (isCompatible(depoly(info.tpe), pt)) {
val tree = Ident(info.name) setPos pos
def fail(reason: String, sym1: Symbol, sym2: Symbol): Tree = {
@@ -1799,12 +1803,14 @@ trait Typers requires Analyzer {
if (settings.debug.value) log("typed implicit "+tree1+":"+tree1.tpe+", pt = "+pt);
val tree2 = adapt(tree1, EXPRmode, pt)
if (settings.debug.value) log("adapted implicit "+tree1.symbol+":"+tree2.tpe+" to "+pt);
- if (!tree2.tpe.isError && info.sym == tree1.symbol) tree2
+ if (tree2.tpe.isError) EmptyTree
+ else if (info.sym == tree1.symbol) tree2
else fail("syms differ: ", tree1.symbol, info.sym)
} catch {
case ex: TypeError => fail(ex.getMessage(), NoSymbol, NoSymbol)
}
} else EmptyTree
+ }
/** Infer implicit argument or view
* @param pos position for error reporting
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index 8d0a7d62ca..3b493a4e6b 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -42,6 +42,14 @@ object Predef {
type NullPointerException = java.lang.NullPointerException
type Throwable = java.lang.Throwable
+/*
+ type ~[a, b] = Tuple2[a, b]
+ class FirstOfPair[a](x: a) {
+ def ~[b](y: b): Tuple2[a, b] = Tuple2(x, y)
+ }
+ implicit def any2firstOfPair[a](x: a): FirstOfPair[a] = new FirstOfPair(x)
+*/
+
type Pair[+a, +b] = Tuple2[a, b]
def Pair[a, b](x: a, y: b) = Tuple2(x, y)