summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala20
-rw-r--r--src/library/scala/collection/immutable/TreeSet.scala17
-rw-r--r--test/pending/pos/unapplyGeneric.scala2
5 files changed, 22 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
index f020e0c6af..fe8efc0977 100644
--- a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
@@ -74,7 +74,7 @@ class ConsoleReporter(reader : BufferedReader, writer : PrintWriter) extends Abs
val buf = new StringBuilder(msg)
buf.insert(0, " ")
if (pos.line != Position.NOLINE)
- buf.insert(0, ":" + pos.line)
+ buf.insert(0, ":"+pos.line+":")
pos match {
case FakePos(msg) =>
buf.insert(0,msg)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 45d7f3f863..94dc40b230 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -626,15 +626,15 @@ trait Infer requires Analyzer {
* @param pt ...
*/
private def substExpr(tree: Tree, undetparams: List[Symbol],
- targs: List[Type], pt: Type): unit =
+ targs: List[Type], pt: Type) {
if (targs eq null) {
if (!tree.tpe.isErroneous && !pt.isErroneous)
error(tree.pos, "polymorphic expression cannot be instantiated to expected type" +
foundReqMsg(PolyType(undetparams, skipImplicit(tree.tpe)), pt))
} else {
- checkBounds(tree.pos, undetparams, targs, "inferred ")
new TreeTypeSubstituter(undetparams, targs).traverse(tree)
}
+ }
/** Substitite free type variables <code>undetparams</code> of application
* <code>fn(args)</code>, given prototype <code>pt</code>.
@@ -655,9 +655,11 @@ trait Infer requires Analyzer {
undetparams, formalTypes(formals, argtpes.length),
restpe, argtpes, pt, uninstantiated)
checkBounds(fn.pos, undetparams, targs, "inferred ")
+ //Console.println("UNAPPLY subst type "+undetparams+" to "+targs+" in "+fn+" ( "+args+ ")")
val treeSubst = new TreeTypeSubstituter(undetparams, targs)
treeSubst.traverse(fn)
treeSubst.traverseTrees(args)
+ //Console.println("UNAPPLY gives "+fn+" ( "+args+ "), argtpes = "+argtpes+", pt = "+pt)
uninstantiated.toList
} catch {
case ex: NoInstance =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 59bcb7efa6..cc6c1dfb00 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -516,7 +516,7 @@ trait Typers requires Analyzer {
val tparams1 = cloneSymbols(tparams)
val tree1 = if (tree.isType) tree
else TypeApply(tree, tparams1 map (tparam =>
- TypeTree(tparam.tpe) setOriginal tree /* setPos tree.pos */)) setPos tree.pos
+ TypeTree(tparam.tpe) setOriginal tree)) setPos tree.pos
context.undetparams = context.undetparams ::: tparams1
adapt(tree1 setType restpe.substSym(tparams, tparams1), mode, pt)
case mt: ImplicitMethodType if ((mode & (EXPRmode | FUNmode | LHSmode)) == EXPRmode) => // (4.1)
@@ -588,9 +588,10 @@ trait Typers requires Analyzer {
}
if (definitions.unapplyMember(consp.tpe).exists)
atPos(tree.pos) {
+ //Console.println("UNAPPLY1: "+gen.mkAttributedRef(tree.tpe.prefix,consp))
gen.mkAttributedRef(tree.tpe.prefix,consp)
}
- // needs member type, but member of what? ^^^
+ // needs member type, but member of what? ^^^`
// see test/pending/pos/unapplyNeedsMemberType.scala
else errorTree(tree, "" + clazz + " is not a case class, nor does it have unapply/unapplySeq method")
} else {
@@ -1152,6 +1153,7 @@ trait Typers requires Analyzer {
*/
def typedCase(cdef: CaseDef, pattpe: Type, pt: Type): CaseDef = {
val pat1: Tree = typedPattern(cdef.pat, pattpe)
+ //Console.println("UNAPPLY3:"+pat1+":"+pat1.tpe)
val guard1: Tree = if (cdef.guard == EmptyTree) EmptyTree
else typed(cdef.guard, BooleanClass.tpe)
var body1: Tree = typed(cdef.body, pt)
@@ -1399,26 +1401,24 @@ trait Typers requires Analyzer {
setError(copy.Apply(tree, fun, args))
/* --- begin unapply --- */
- // bq: this is so wrong -- why use WildcardTypes to check patterns arguments?
- // only because of generics?
case otpe if definitions.unapplyMember(otpe).exists && settings.Xunapply.value =>
// !!! this is fragile, maybe needs to be revised when unapply patterns become terms
val unapp = definitions.unapplyMember(otpe)
assert(unapp.exists, tree)
- assert(isFullyDefined(pt))
+ // this is no longer needed!
val unappArg:Type = unapp.tpe match {
case PolyType(_,MethodType(List(res), _)) => res
case MethodType(List(res), _) => res
case _ => error(fun.pos, "unapply takes too many arguments to be used as pattern"); NoType
}
-
+ val argDummyType = pt // was unappArg
val argDummy = context.owner.newValue(fun.pos, nme.SELECTOR_DUMMY)
.setFlag(SYNTHETIC)
- .setInfo(unappArg) // was: pt
+ .setInfo(argDummyType)
if (args.length > MaxTupleArity)
error(fun.pos, "too many arguments for unapply pattern, maximum = "+MaxTupleArity)
- val arg = Ident(argDummy) setType unappArg // was pt
+ val arg = Ident(argDummy) setType argDummyType
var funPt: Type = null
try {
funPt = unapp.name match {
@@ -1440,14 +1440,14 @@ trait Typers requires Analyzer {
val fun1untyped = atPos(fun.pos) {
Apply(Select(gen.mkAttributedRef(fun.tpe.prefix,fun.symbol), unapp), List(arg))
}
- //Console.println("UNAPP "+fun+"/"+fun.tpe+" "+fun1untyped)
- //Console.println("funPt: "+funPt)
+ //Console.println("UNAPPLY2 "+fun+"/"+fun.tpe+" "+fun1untyped+", funPt = "+funPt)
val fun1 = typed(fun1untyped, EXPRmode, funPt)
if (fun1.tpe.isErroneous) setError(tree)
else {
val formals0 = unapplyTypeList(fun1.symbol, fun1.tpe)
val formals1 = formalTypes(formals0, args.length)
val args1 = typedArgs(args, mode, formals0, formals1)
+ if (!isFullyDefined(pt)) assert(false, tree+" ==> "+UnApply(fun1, args1)+", pt = "+pt)
UnApply(fun1, args1) setPos tree.pos setType pt
}
/* --- end unapply --- */
diff --git a/src/library/scala/collection/immutable/TreeSet.scala b/src/library/scala/collection/immutable/TreeSet.scala
index e17763c663..1226923d66 100644
--- a/src/library/scala/collection/immutable/TreeSet.scala
+++ b/src/library/scala/collection/immutable/TreeSet.scala
@@ -34,21 +34,16 @@ object TreeSet {
*/
[serializable]
-class TreeSet[A <% Ordered[A]] extends Set[A] {
+class TreeSet[A <% Ordered[A]](val size: int, t: RedBlack[A]#Tree[Unit])
+extends RedBlack[A] with Set[A] {
- def size: int = 0
+ def isSmaller(x: A, y: A) = x < y
- val rb = new RedBlack[A] {
- def isSmaller(x: A, y: A) = x < y
- }
+ def this() = this(0, null)
- def tree: rb.Tree[Unit] = rb.Empty
+ protected val tree: RedBlack[A]#Tree[Unit] = if (size == 0) Empty else t
- private def newSet[B](s: int, t: rb.Tree[Unit]) = new TreeSet[A] {
- override val size = s
- override val rb: TreeSet.this.rb.type = TreeSet.this.rb
- override val tree = t
- }
+ private def newSet(s: int, t: RedBlack[A]#Tree[Unit]) = new TreeSet[A](s, t)
/** A factory to create empty maps of the same type of keys.
*/
diff --git a/test/pending/pos/unapplyGeneric.scala b/test/pending/pos/unapplyGeneric.scala
index 3798d0b466..bf88816885 100644
--- a/test/pending/pos/unapplyGeneric.scala
+++ b/test/pending/pos/unapplyGeneric.scala
@@ -5,7 +5,7 @@ object Bar {
class Bar[A,B](val _1:A, val _2:B) extends Product2[A,B]
object Test {
- Bar(2, 'a') match {
+ new Bar(2, 'a') match {
case Bar(x,y) =>
}
}