summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-07-03 16:50:24 +0000
committerMartin Odersky <odersky@gmail.com>2007-07-03 16:50:24 +0000
commite4bc488dea80c032497e2f9cd0165da1b779dc9e (patch)
tree87463a8b7c79ffcb5abb72b73272aaba4cde43cc
parent72597908f803fbf709bf8af8379ca10c7cfd7639 (diff)
downloadscala-e4bc488dea80c032497e2f9cd0165da1b779dc9e.tar.gz
scala-e4bc488dea80c032497e2f9cd0165da1b779dc9e.tar.bz2
scala-e4bc488dea80c032497e2f9cd0165da1b779dc9e.zip
fixed bug 1192, 1168, plus a problem with exist...
fixed bug 1192, 1168, plus a problem with existentials
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeInfo.scala18
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala32
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
4 files changed, 50 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
index af98036536..20ea71baba 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -205,12 +205,22 @@ abstract class TreeInfo {
/** Is this pattern node a catch-all or type-test pattern? */
def isCatchCase(cdef: CaseDef) = cdef match {
- case CaseDef(Typed(Ident(nme.WILDCARD), tpt), EmptyTree, _) => isSimple(tpt.tpe)
- case CaseDef(Bind(_, Typed(Ident(nme.WILDCARD), tpt)), EmptyTree, _) => isSimple(tpt.tpe)
- case _ => isDefaultCase(cdef)
+ case CaseDef(Typed(Ident(nme.WILDCARD), tpt), EmptyTree, _) =>
+ isSimpleThrowable(tpt.tpe)
+ case CaseDef(Bind(_, Typed(Ident(nme.WILDCARD), tpt)), EmptyTree, _) =>
+ isSimpleThrowable(tpt.tpe)
+ case _ =>
+ isDefaultCase(cdef)
+ }
+
+ private def isSimpleThrowable(tp: Type): boolean = tp match {
+ case TypeRef(pre, sym, args) =>
+ (pre == NoPrefix || pre.widen.symbol.isStatic) &&
+ (sym isNonBottomSubClass definitions.ThrowableClass)
+ case _ =>
+ false
}
- private def isSimple(tp: Type): boolean = true
/* If we have run-time types, and these are used for pattern matching,
we should replace this by something like:
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index dc1bcd720e..c2e0d8fd82 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -660,7 +660,7 @@ trait Parsers {
*/
def requiresTypeOpt(): Tree =
if (inToken == REQUIRES) {
- warning("`requires T' has been deprecated; use `{ self: T => ...' instead")
+ in.deprecationWarning(in.pos, "`requires T' has been deprecated; use `{ self: T => ...' instead")
inNextToken; placeholderTypeBoundary(annotType(false))
} else TypeTree()
@@ -671,8 +671,12 @@ trait Parsers {
val ts = new ListBuffer[Tree] + argType(isPattern)
while (inToken == COMMA) {
inNextToken
- if (inToken == RPAREN) return List(makeTupleType(ts.toList, false))
- ts += argType(isPattern)
+ if (inToken == RPAREN) {
+ in.deprecationWarning(in.pos, "Trailing commas have been deprecated")
+ return ts.toList
+ } else {
+ ts += argType(isPattern)
+ }
}
ts.toList
}
@@ -897,8 +901,12 @@ trait Parsers {
val ts = new ListBuffer[Tree] + expr()
while (inToken == COMMA) {
inNextToken;
- if (inToken == RPAREN) return List(makeTupleTerm(ts.toList, false))
- ts += expr()
+ if (inToken == RPAREN) {
+ in.deprecationWarning(in.pos, "Trailing commas have been deprecated")
+ return ts.toList
+ } else {
+ ts += expr()
+ }
}
ts.toList
}
@@ -1009,7 +1017,7 @@ trait Parsers {
Throw(expr())
}
case DOT =>
- warning("`.f' has been deprecated; use `_.f' instead")
+ in.deprecationWarning(in.pos, "`.f' has been deprecated; use `_.f' instead")
atPos(inSkipToken) {
if (isIdent) {
makeDotClosure(stripParens(simpleExpr()))
@@ -1120,7 +1128,7 @@ trait Parsers {
val name = unaryOp()
atPos(pos) { Select(stripParens(simpleExpr()), name) }
} else if (isIdent && inName == AMP) {
- warning("`&f' has been deprecated; use `f _' instead")
+ in.deprecationWarning(in.pos, "`&f' has been deprecated; use `f _' instead")
val pos = inCurrentPos
val name = ident()
atPos(pos) { Typed(stripParens(simpleExpr()), Function(List(), EmptyTree)) }
@@ -1315,8 +1323,12 @@ trait Parsers {
val ts = new ListBuffer[Tree] + pattern(seqOK)
while (inToken == COMMA) {
inNextToken;
- if (inToken == RPAREN) return List(makeTupleTerm(ts.toList, false))
- ts += pattern(seqOK)
+ if (inToken == RPAREN) {
+ in.deprecationWarning(in.pos, "Trailing commas have been deprecated")
+ return ts.toList
+ } else {
+ ts += pattern(seqOK)
+ }
}
ts.toList
}
@@ -2035,7 +2047,7 @@ trait Parsers {
* | ConstrBlock
*/
def constrExpr(vparamss: List[List[ValDef]]): Tree =
- if (inToken == LBRACE) constrBlock(vparamss) else Block(List(selfInvocation(vparamss)), Literal())
+ if (inToken == LBRACE) constrBlock(vparamss) else Block(List(selfInvocation(vparamss)), Literal(()))
/** SelfInvocation ::= this ArgumentExprs {ArgumentExprs}
*/
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 693a781546..cf18afc66a 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1185,6 +1185,7 @@ trait Types {
private var closureDepthCache: Int = _
override def isStable: Boolean = {
+ sym == SingletonClass ||
sym.isAbstractType && (sym.info.bounds.hi.symbol isSubClass SingletonClass)
}
@@ -2235,6 +2236,18 @@ A type's symbol should never be inspected directly.
def apply(tp: Type): Type = if (tp eq from) to else mapOver(tp)
}
+ class SubstWildcardMap(from: List[Symbol]) extends TypeMap {
+ def apply(tp: Type): Type = try {
+ tp match {
+ case TypeRef(_, sym, _) if (from contains sym) => WildcardType
+ case _ => mapOver(tp)
+ }
+ } catch {
+ case ex: MalformedType =>
+ WildcardType
+ }
+ }
+
class InstantiateDeBruijnMap(actuals: List[Type]) extends TypeMap {
def apply(tp: Type): Type = tp match {
case DeBruijnIndex(level, pid) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index cd668cd201..f3ca3a5734 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2757,7 +2757,7 @@ trait Typers { self: Analyzer =>
def dropExistential(tp: Type): Type = tp match {
case ExistentialType(tparams, tpe) =>
if (settings.debug.value) println("drop ex "+tree+" "+tp)
- tpe.subst(tparams, tparams map (x => WildcardType))
+ new SubstWildcardMap(tparams).apply(tp)
case TypeRef(_, sym, _)if sym.isAliasType =>
dropExistential(tp.normalize)
case _ => tp