summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-06-24 12:45:25 +0000
committerMartin Odersky <odersky@gmail.com>2008-06-24 12:45:25 +0000
commitb0c36c7a7c646caf95c7cda4a91681d243a0508d (patch)
treedc8d173de52c9c0f4bafd8db473b0e6431007f84
parentd8b12acb937667e1356af049c594302fa120f656 (diff)
downloadscala-b0c36c7a7c646caf95c7cda4a91681d243a0508d.tar.gz
scala-b0c36c7a7c646caf95c7cda4a91681d243a0508d.tar.bz2
scala-b0c36c7a7c646caf95c7cda4a91681d243a0508d.zip
lazy vals cannot override strict vals and vice ...
lazy vals cannot override strict vals and vice versa; fixed initialization bugs that caused scala and fsc to fail.
-rw-r--r--build.xml4
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala6
-rw-r--r--src/compiler/scala/tools/nsc/GenericRunnerCommand.scala2
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala6
-rw-r--r--src/compiler/scala/tools/nsc/IdeSupport.scala5
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterCommand.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala9
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
-rw-r--r--test/files/neg/lazyvals.scala20
-rw-r--r--test/files/run/lazy-override.check4
-rw-r--r--test/files/run/lazy-override.scala7
12 files changed, 47 insertions, 23 deletions
diff --git a/build.xml b/build.xml
index 5b3da09dfa..c101f3b539 100644
--- a/build.xml
+++ b/build.xml
@@ -123,10 +123,10 @@ INITIALISATION
<condition property="os.win">
<os family="windows"/>
</condition>
- <!-- Finding out SVN revision -->
+ <!-- Finding out SVN revision
<exec executable="svn" outputproperty="svn.out">
<arg line=" info ${basedir}"/>
- </exec>
+ </exec> -->
<propertyregex
property="svn.number" input="${svn.out}" select="\1"
regexp="Revision: ([0-9]+)"
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala
index 0a3e47f8e9..6bac62aefd 100644
--- a/src/compiler/scala/tools/nsc/CompileClient.scala
+++ b/src/compiler/scala/tools/nsc/CompileClient.scala
@@ -8,8 +8,6 @@ package scala.tools.nsc
import java.io.{BufferedReader, File, InputStreamReader, PrintWriter}
-import scala.tools.util.StringOps
-
/** The client part of the fsc offline compiler. Instead of compiling
* things itself, it send requests to a CompileServer.
*/
@@ -39,12 +37,12 @@ class StandardCompileClient {
val fileEnding = Properties.fileEndingString
protected def normalize(args: Array[String]): (String, String) = {
- var i = 0
+ var i = 0
val vmArgs = new StringBuilder
var serverAdr = ""
while (i < args.length) {
val arg = args(i)
- if (arg endsWith fileEnding) {
+ if (fileEnding split ("\\|") exists (arg endsWith _)) {
args(i) = absFileName(arg)
} else if (arg startsWith "-J") {
//see http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html#J
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
index 520d1b6055..094b2b4d1f 100644
--- a/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
+++ b/src/compiler/scala/tools/nsc/GenericRunnerCommand.scala
@@ -50,6 +50,8 @@ extends CompilerCommand(allargs, settings, error, false)
}
}
+ processArguments()
+
override def usageMsg = {
cmdName + " [ <option> ]... [<torun> <arguments>]\n" +
"\n" +
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 62836bc91c..fb346899cb 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -225,9 +225,9 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
getSourceFile(ret.sourceFile)
}
- val loaders : SymbolLoaders { val global : Global.this.type } = new SymbolLoaders {//change?
- lazy val global: Global.this.type = Global.this
- }
+ lazy val loaders : SymbolLoaders { val global : Global.this.type } = new {
+ val global: Global.this.type = Global.this
+ } with SymbolLoaders
def rootLoader: LazyType =
if (forMSIL) new loaders.NamespaceLoader(classPath.root)
diff --git a/src/compiler/scala/tools/nsc/IdeSupport.scala b/src/compiler/scala/tools/nsc/IdeSupport.scala
index ac80997f18..2f68ee5d01 100644
--- a/src/compiler/scala/tools/nsc/IdeSupport.scala
+++ b/src/compiler/scala/tools/nsc/IdeSupport.scala
@@ -23,8 +23,9 @@ trait IdeSupport extends Global with symtab.IdeSupport {
normalCompile(run.compileSources(source :: Nil))
run.units.find(unit => unit.source == source)
}
- object loaders1 extends scala.tools.nsc.symtab.SymbolLoaders {
- lazy val global : IdeSupport.this.type = IdeSupport.this
+ object loaders1 extends {
+ val global : IdeSupport.this.type = IdeSupport.this
+ } with scala.tools.nsc.symtab.SymbolLoaders {
import global._
protected override def completeClassfile(root : global.Symbol, loader : ClassfileLoader)(f : => Unit) : Unit =
global.normalCompile(f)
diff --git a/src/compiler/scala/tools/nsc/InterpreterCommand.scala b/src/compiler/scala/tools/nsc/InterpreterCommand.scala
index 8f9a104a9e..036e640c88 100644
--- a/src/compiler/scala/tools/nsc/InterpreterCommand.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterCommand.scala
@@ -14,5 +14,5 @@ package scala.tools.nsc
class InterpreterCommand(arguments: List[String], error: String => Unit)
extends CompilerCommand(arguments, new Settings(error), error, false) {
override val cmdName = "scala"
- override val fileEnding = ".scalaint"
+ override lazy val fileEnding = ".scalaint"
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index caaecc1b90..ac35ecc052 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -982,6 +982,8 @@ trait Namers { self: Analyzer =>
context.error(sym.pos, "`override' modifier not allowed for constructors")
if (sym.hasFlag(ABSOVERRIDE) && !sym.owner.isTrait)
context.error(sym.pos, "`abstract override' modifier only allowed for members of traits")
+ if (sym.hasFlag(LAZY) && sym.hasFlag(PRESUPER))
+ context.error(sym.pos, "`lazy' definitions may not be initialized early")
if (sym.info.typeSymbol == FunctionClass(0) &&
sym.isValueParameter && sym.owner.isClass && sym.owner.hasFlag(CASE))
context.error(sym.pos, "pass-by-name arguments not allowed for case class parameters");
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 0e2227e3ed..26e584e2e4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -186,9 +186,12 @@ abstract class RefChecks extends InfoTransform {
overrideError("cannot override a mutable variable")
} else if (other.isStable && !member.isStable) { // (1.4)
overrideError("needs to be an immutable value")
-// } else if (other.isStable && !other.isDeferred && other.owner.isTrait && (member hasFlag OVERRIDE)) {
-// overrideError("cannot override a value or variable definition in a trait " +
-// "\n (this is an implementation restriction)")
+ } else if (member.isValue && (member hasFlag LAZY) &&
+ other.isValue && !other.isSourceMethod && !other.isDeferred && !(other hasFlag LAZY)) {
+ overrideError("cannot override a concrete non-lazy value")
+ } else if (other.isValue && (other hasFlag LAZY) && !other.isSourceMethod && !other.isDeferred &&
+ member.isValue && !(member hasFlag LAZY)) {
+ overrideError("must be declared lazy to override a concrete lazy value")
} else {
if (other.isAliasType) {
//if (!member.typeParams.isEmpty) // (1.5) @MAT
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2740d8944d..5d61928388 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -331,7 +331,8 @@ trait Typers { self: Analyzer =>
}
def checkRegPatOK(pos: Position, mode: Int) =
- if ((mode & REGPATmode) == 0)
+ if ((mode & REGPATmode) == 0 &&
+ phase.id <= currentRun.typerPhase.id) // fixes t1059
error(pos, "no regular expression pattern allowed here\n"+
"(regular expression patterns are only allowed in arguments to *-parameters)")
diff --git a/test/files/neg/lazyvals.scala b/test/files/neg/lazyvals.scala
index 8514d42c13..f92534f506 100644
--- a/test/files/neg/lazyvals.scala
+++ b/test/files/neg/lazyvals.scala
@@ -24,3 +24,23 @@ class Lazy {
// no lazy modifiers in class parameters
class A(lazy val obj: Object) {}
}
+
+object T2 {
+ class A {
+ val x: Int = { print("/*A.x*/"); 2 }
+ lazy val y: Int = { print("/*A.y*/"); 2 }
+ }
+
+
+ class B extends A {
+ // lazy overrides strict val
+ override lazy val x: Int = { print("/*B.x*/"); 3 }
+ // strict val overrides lazy
+ override val y: Int = { print("/*B.y*/"); 3 }
+ }
+}
+
+
+
+
+
diff --git a/test/files/run/lazy-override.check b/test/files/run/lazy-override.check
index 225a9b120d..a8f658d7b5 100644
--- a/test/files/run/lazy-override.check
+++ b/test/files/run/lazy-override.check
@@ -1,3 +1,3 @@
-/*A.x*/a.x=2
-/*A.x*//*B.y*/b.x=/*B.x*/3
+a.x=/*A.x*/2
+b.x=/*B.x*/3
b.z=/*B.z/3
diff --git a/test/files/run/lazy-override.scala b/test/files/run/lazy-override.scala
index 0b72f60f03..e5884257a8 100644
--- a/test/files/run/lazy-override.scala
+++ b/test/files/run/lazy-override.scala
@@ -1,15 +1,12 @@
class A {
- val x: Int = { print("/*A.x*/"); 2 }
+ lazy val x: Int = { print("/*A.x*/"); 2 }
lazy val y: Int = { print("/*A.y*/"); 2 }
lazy val z: Int = { print("/*A.z*/"); 2 }
}
class B extends A {
- // lazy overrides strict val
override lazy val x: Int = { print("/*B.x*/"); 3 }
- // strict val overrides lazy
- override val y: Int = { print("/*B.y*/"); 3 }
- // lazy overrides lazy
+ override lazy val y: Int = { print("/*B.y*/"); 3 }
override lazy val z: Int = { print("/*B.z/"); 3 }
}