diff options
author | Martin Odersky <odersky@gmail.com> | 2006-06-28 19:51:19 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-06-28 19:51:19 +0000 |
commit | b8a3d27064b8c3e9303fb88db6ef1013e9e9965a (patch) | |
tree | a1f68e83c3a5cba938e6638bd013edbca219c957 | |
parent | 4757cf7f35e4593a791d8baf4d9f00c972913645 (diff) | |
download | scala-b8a3d27064b8c3e9303fb88db6ef1013e9e9965a.tar.gz scala-b8a3d27064b8c3e9303fb88db6ef1013e9e9965a.tar.bz2 scala-b8a3d27064b8c3e9303fb88db6ef1013e9e9965a.zip |
Fixed pattern matching bugs 401, 643
Added multiline string literals
Some small refactoring
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileSocket.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 52 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/models/SemanticTokens.scala | 28 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 9 | ||||
-rw-r--r-- | src/library/scala/Predef.scala | 2 |
6 files changed, 78 insertions, 25 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index 5549cf18b7..d8abd33ae6 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -117,7 +117,7 @@ object CompileSocket { Thread.sleep(100) val result = getsock(attempts - 1) if (attempts == nAttempts) - System.err.println("... connection established at port "+port) + System.err.println("...connection established at port "+port+"...") result } } diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 9566198d18..0ddc56e586 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -431,19 +431,21 @@ trait Trees requires Global { case class Typed(expr: Tree, tpt: Tree) extends TermTree; - abstract class GenericApply(val fun0: Tree, val args0: List[Tree]) extends TermTree; - + abstract class GenericApply extends TermTree { + val fun: Tree + val args: List[Tree] + } /** Type application */ case class TypeApply(fun: Tree, args: List[Tree]) - extends GenericApply(fun, args) { + extends GenericApply { override def symbol: Symbol = fun.symbol override def symbol_=(sym: Symbol): unit = { fun.symbol = sym } } /** Value application */ case class Apply(fun: Tree, args: List[Tree]) - extends GenericApply(fun, args) { + extends GenericApply { override def symbol: Symbol = fun.symbol override def symbol_=(sym: Symbol): unit = { fun.symbol = sym } } diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 0e1a028bd2..f329bcbc36 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -65,10 +65,10 @@ trait Scanners requires SyntaxAnalyzer { /** append Unicode character to "lit" buffer */ - protected def putChar(c: char) = cbuf.append(c) + protected def putChar(c: char): unit = cbuf.append(c) /** Clear buffer and set name */ - private def setName = { + private def setName: unit = { name = newTermName(cbuf.toString()) cbuf.setLength(0) } @@ -271,18 +271,31 @@ trait Scanners requires SyntaxAnalyzer { base = 8 } getNumber - return; // scala-mode: return is a keyword + return case '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => base = 10 getNumber return - case '`' => //" scala-mode: need to understand literals + case '`' => + in.next getStringLit('`') token = IDENTIFIER return - case '\"' => //" scala-mode: need to understand literals - getStringLit('\"') + case '\"' => + in.next + if (in.ch == '\"') { + in.next + if (in.ch == '\"') { + in.next + getMultiLineStringLit + } else { + token = STRINGLIT + name = nme.EMPTY + } + } else { + getStringLit('\"') + } return case '\'' => in.next @@ -549,7 +562,6 @@ trait Scanners requires SyntaxAnalyzer { } private def getStringLit(delimiter: char): unit = { - in.next while (in.ch != delimiter && (in.isUnicode || in.ch != CR && in.ch != LF && in.ch != SU)) { getlitch() } @@ -562,6 +574,32 @@ trait Scanners requires SyntaxAnalyzer { } } + private def getMultiLineStringLit: unit = + if (in.ch == '\"') { + in.next + if (in.ch == '\"') { + in.next + if (in.ch == '\"') { + in.next + token = STRINGLIT + setName + } else { + putChar('\"') + putChar('\"') + getMultiLineStringLit + } + } else { + putChar('\"') + getMultiLineStringLit + } + } else if (in.ch == SU) { + syntaxError("unclosed multi-line string literal") + } else { + putChar(in.ch) + in.next + getMultiLineStringLit + } + // Literals ----------------------------------------------------------------- /** read next character in character or string literal: diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala index a4424ab2af..32386c2b47 100644 --- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala +++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala @@ -411,26 +411,28 @@ class SemanticTokens(val compiler: Global) { } case tree : TypeApply => //System.err.println("TYPE_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); - if (!tree.args0.isEmpty) { + if (!tree.args.isEmpty) { //System.err.println("ARGS: " + unit.source.dbg(tree.args0.head.pos)); } - build(tree.fun0); - build(tree.args0); + build(tree.fun); + build(tree.args); case tree : Apply => //System.err.println("NORM_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); - build(tree.fun0); - build(tree.args0); + build(tree.fun); + build(tree.args); case tree : GenericApply => //System.err.println("GEN_APPLY: " + tree + " " + unit.source.dbg(tree.pos)); - build(tree.fun0); - build(tree.args0); - case tree : Typed => build(tree.expr); build(tree.tpt); + build(tree.fun); + build(tree.args); + case tree : Typed => + build(tree.expr); + build(tree.tpt); case tree : Block => - if (false) { - if (!tree.stats.isEmpty) - System.err.println("BLOCKS: " + tree.stats.head + " " + tree.stats.head.getClass()); - System.err.println("BLOCKE: " + tree.expr + " " + tree.expr.getClass()); - } + if (false) { + if (!tree.stats.isEmpty) + System.err.println("BLOCKS: " + tree.stats.head + " " + tree.stats.head.getClass()); + System.err.println("BLOCKE: " + tree.expr + " " + tree.expr.getClass()); + } build(tree.stats); build(tree.expr); case tree : CaseDef => build(tree.pat); build(tree.guard); build(tree.body); diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 9039b6b5c8..39d9081fef 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -360,6 +360,15 @@ abstract class UnCurry extends InfoTransform { } else { withNeedLift(true) { val formals = fn.tpe.paramTypes; + if (inPattern && fn.symbol != null && fn.symbol.isSubClass(SeqClass)) { + // normalization to fix bug401 + val tpe1 = tree.tpe.baseType(fn.symbol) + tree.setType(tpe1) + fn.setType( + fn.tpe match { + case MethodType(formals, restpe) => MethodType(formals, tpe1) + }) + } copy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, args, formals))) } } diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 3b493a4e6b..e33a2cc8df 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -211,6 +211,8 @@ object Predef { implicit def intWrapper(x: int) = new runtime.RichInt(x) + implicit def stringWrapper(x: String) = new runtime.RichString(x) + implicit def char2ordered(x: char): Ordered[char] = new Ordered[char] with Proxy { def self: Any = x def compare [b >: char <% Ordered[b]](y: b): int = y match { |