summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-01-09 19:39:31 +0000
committerMartin Odersky <odersky@gmail.com>2007-01-09 19:39:31 +0000
commitf75cbd338f81a00ab9696fb0482fd561ce1a0826 (patch)
treee42d6f72e23be6c823d4408c07d5fa92791c8499
parent6835f1377b16ef8d42850dade06ee840e0f2c35a (diff)
downloadscala-f75cbd338f81a00ab9696fb0482fd561ce1a0826.tar.gz
scala-f75cbd338f81a00ab9696fb0482fd561ce1a0826.tar.bz2
scala-f75cbd338f81a00ab9696fb0482fd561ce1a0826.zip
fixed bugs 880, 877, 876, 875, Added capitalize...
fixed bugs 880, 877, 876, 875, Added capitalize method to RichString
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala23
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala13
-rw-r--r--src/library/scala/runtime/RichString.scala49
5 files changed, 52 insertions, 36 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 454eed1755..d8ca5d73a1 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1925,7 +1925,7 @@ trait Parsers requires SyntaxAnalyzer {
val parent = simpleType(false)
// System.err.println("classTempl: " + parent)
parents += parent
- if (in.token == LPAREN)
+ if (in.token == LPAREN && !mods.hasFlag(Flags.TRAIT))
do { argss += argumentExprs() } while (in.token == LPAREN)
else argss += List()
while (in.token == WITH) {
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index fee88151f2..be740910ef 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -173,6 +173,7 @@ trait StdNames requires SymbolTable {
val MINUS = encode("-")
val PLUS = encode("+")
+ val PLUSPLUS = encode("++")
val TILDE = encode("~")
val EQEQ = encode("==")
val BANG = encode("!")
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 05bd8b664d..9d3180f0f2 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -277,19 +277,30 @@ abstract class UnCurry extends InfoTransform with TypingTransformers {
val args1 =
formals.last match {
case TypeRef(pre, sym, List(elempt)) if (sym == RepeatedParamClass) =>
- def mkArrayValue(ts: List[Tree]) =
+ def mkArrayValue(ts: List[Tree]): Tree =
atPos(pos)(ArrayValue(TypeTree(elempt), ts) setType formals.last);
-
+ def mkConcat(left: Tree, right: Tree): Tree =
+ atPos(pos) {
+ localTyper.typed {
+ Apply(
+ TypeApply(
+ Select(left, nme.PLUSPLUS),
+ List(TypeTree(elempt))),
+ List(right))
+ } setType formals.last
+ }
if (args.isEmpty)
List(mkArrayValue(args))
else {
- val suffix: Tree = args.last match {
+ val {fixedArgs, varArgs} = args.splitAt(formals.length - 1)
+ val suffix = args.last match {
case Typed(arg, Ident(name)) if name == nme.WILDCARD_STAR.toTypeName =>
- arg setType seqType(arg.tpe)
+ if (varArgs.length > 1) mkConcat(ArrayValue(TypeTree(elempt), varArgs.init), arg)
+ else arg setType seqType(arg.tpe)
case _ =>
- mkArrayValue(args.drop(formals.length - 1))
+ mkArrayValue(varArgs)
}
- args.take(formals.length - 1) ::: List(suffix)
+ fixedArgs ::: List(suffix)
}
case _ => args
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index cc6c1dfb00..be33fb215d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -459,11 +459,10 @@ trait Typers requires Analyzer {
case Select(qual, _) => qual.tpe
case _ => NoPrefix
}
- if (tree.tpe.isInstanceOf[MethodType] && pre.isStable &&
- (pt.isStable || (mode & QUALmode) != 0 && !sym.isConstant || sym.isModule)) {
- assert(sym.tpe.paramTypes.isEmpty)
- tree.setType(MethodType(List(), singleType(pre, sym)))
- } else tree
+ if (tree.tpe.isInstanceOf[MethodType] && pre.isStable && sym.tpe.paramTypes.isEmpty &&
+ (pt.isStable || (mode & QUALmode) != 0 && !sym.isConstant || sym.isModule))
+ tree.setType(MethodType(List(), singleType(pre, sym)))
+ else tree
}
/** Perform the following adaptations of expression, pattern or type `tree' wrt to
@@ -1693,9 +1692,9 @@ trait Typers requires Analyzer {
else cx.depth - (cx.scope.nestingLevel - defEntry.owner.nestingLevel)
var impSym: Symbol = NoSymbol; // the imported symbol
var imports = context.imports; // impSym != NoSymbol => it is imported from imports.head
- while (impSym == NoSymbol && !imports.isEmpty && imports.head.depth > symDepth) {
+ while (!impSym.exists && !imports.isEmpty && imports.head.depth > symDepth) {
impSym = imports.head.importedSymbol(name)
- if (impSym == NoSymbol) imports = imports.tail
+ if (!impSym.exists) imports = imports.tail
}
// detect ambiguous definition/import,
diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala
index 474fdf947d..8016b59adf 100644
--- a/src/library/scala/runtime/RichString.scala
+++ b/src/library/scala/runtime/RichString.scala
@@ -14,24 +14,21 @@ package scala.runtime
import Predef._
-final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[String] {
-
- // Proxy
- def self: Any = s
+final class RichString(val self: String) extends Proxy with Seq[Char] with Ordered[String] {
// Ordered[String]
- def compare(other: String) = s compareTo other
+ def compare(other: String) = self compareTo other
// Seq[Char]
- def length = s.length()
- def elements = Iterator.fromString(s)
+ def length = self.length()
+ def elements = Iterator.fromString(self)
/** Retrieve the n-th character of the string
*
* @param index into the string
* @return the character at position <code>index</code>.
*/
- def apply(n: Int) = s charAt n
+ def apply(n: Int) = self charAt n
private final val LF: Char = 0x0A
private final val FF: Char = 0x0C
@@ -54,14 +51,14 @@ final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[Stri
* </p>
*/
def stripLineEnd: String = {
- val len = s.length
- if (len == 0) s
+ val len = self.length
+ if (len == 0) self
else {
val last = apply(len - 1)
if (isLineBreak(last))
- s.substring(0, if (last == LF && len >= 2 && apply(len - 2) == CR) len - 2 else len - 1)
+ self.substring(0, if (last == LF && len >= 2 && apply(len - 2) == CR) len - 2 else len - 1)
else
- s
+ self
}
}
@@ -80,7 +77,7 @@ final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[Stri
* </ul>
*/
def linesWithSeparators = new Iterator[String] {
- val len = s.length
+ val len = self.length
var index = 0
def hasNext: Boolean = index <= len
def next: String = {
@@ -88,7 +85,7 @@ final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[Stri
val start = index
while (index < len && !isLineBreak(apply(index))) index = index + 1
index = index + 1
- s.substring(start, index min len)
+ self.substring(start, index min len)
}
}
@@ -96,7 +93,15 @@ final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[Stri
* end characters, i.e. apply <code>.stripLineEnd</code> to all lines
* returned by <code>linesWithSeparators</code>.
*/
- def lines = linesWithSeparators map (line => new RichString(line).stripLineEnd)
+ def lines: Iterator[String] =
+ linesWithSeparators map (line => new RichString(line).stripLineEnd)
+
+ /** Returns this string with first character converted to upper case */
+ def capitalize: String = {
+ val chars = self.toCharArray
+ chars(0) = chars(0).toUpperCase
+ new String(chars)
+ }
/** <p>
* For every line in this string:
@@ -128,13 +133,13 @@ final class RichString(s: String) extends Proxy with Seq[Char] with Ordered[Stri
*/
def stripMargin: String = stripMargin('|')
- def split(separator: Char): Array[String] = s.split(separator.toString())
+ def split(separator: Char): Array[String] = self.split(separator.toString())
- def toByte: Byte = java.lang.Byte.parseByte(s)
- def toShort: Short = java.lang.Short.parseShort(s)
- def toInt: Int = java.lang.Integer.parseInt(s)
- def toLong: Long = java.lang.Long.parseLong(s)
- def toFloat: Float = java.lang.Float.parseFloat(s)
- def toDouble: Double = java.lang.Double.parseDouble(s)
+ def toByte: Byte = java.lang.Byte.parseByte(self)
+ def toShort: Short = java.lang.Short.parseShort(self)
+ def toInt: Int = java.lang.Integer.parseInt(self)
+ def toLong: Long = java.lang.Long.parseLong(self)
+ def toFloat: Float = java.lang.Float.parseFloat(self)
+ def toDouble: Double = java.lang.Double.parseDouble(self)
}