diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/io/AbstractFile.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/PlainFile.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/VirtualFile.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/ZipArchive.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Mixin.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/SourceFile.scala | 15 | ||||
-rw-r--r-- | test/files/neg/volatile.check | 7 | ||||
-rw-r--r-- | test/files/neg/volatile.scala | 24 |
9 files changed, 54 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index 26782dfeb9..f408382b85 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -121,7 +121,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { def output: OutputStream /** size of this file if it is a concrete file. */ - def size: Option[Int] = None + def sizeOption: Option[Int] = None /** returns contents of file (if applicable) in a byte array. * warning: use <code>Global.getSourceFile()</code> to use the proper @@ -138,7 +138,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { @throws(classOf[IOException]) final def toByteArray: Array[Byte] = { val in = input - var rest = size.get + var rest = sizeOption.get val arr = new Array[Byte](rest) while (rest > 0) { val res = in.read(arr, arr.length - rest, rest) diff --git a/src/compiler/scala/tools/nsc/io/PlainFile.scala b/src/compiler/scala/tools/nsc/io/PlainFile.scala index 924822401e..e79af58874 100644 --- a/src/compiler/scala/tools/nsc/io/PlainFile.scala +++ b/src/compiler/scala/tools/nsc/io/PlainFile.scala @@ -39,7 +39,7 @@ class PlainFile(val file: File) extends AbstractFile { override def input = new FileInputStream(file) override def output = new FileOutputStream(file) - override def size = Some(file.length.toInt) + override def sizeOption = Some(file.length.toInt) override def hashCode(): Int = fpath.hashCode diff --git a/src/compiler/scala/tools/nsc/io/VirtualFile.scala b/src/compiler/scala/tools/nsc/io/VirtualFile.scala index f8fcb0eba1..12a4d6aaf4 100644 --- a/src/compiler/scala/tools/nsc/io/VirtualFile.scala +++ b/src/compiler/scala/tools/nsc/io/VirtualFile.scala @@ -50,7 +50,7 @@ class VirtualFile(val name: String, _path: String) extends AbstractFile { /** Returns null. */ final def file: File = null - override def size: Option[Int] = Some(content.size) + override def sizeOption: Option[Int] = Some(content.size) def input : InputStream = new ByteArrayInputStream(content); diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index 2c7eadc19e..dacfc0dd79 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -206,7 +206,7 @@ final class ZipArchive(file: File, val archive: ZipFile) extends PlainFile(file) def archive = ZipArchive.this.archive override def lastModified: Long = entry.getTime() override def input = archive.getInputStream(entry) - override def size = Some(entry.getSize().toInt) + override def sizeOption = Some(entry.getSize().toInt) } } @@ -337,6 +337,6 @@ final class URLZipArchive(url: URL) extends AbstractFile { extends Entry(name, path) { override def lastModified: Long = entry.getTime() override def input = in - override def size = Some(entry.getSize().toInt) + override def sizeOption = Some(entry.getSize().toInt) } } diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index ab020716d2..79c1c490a7 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -960,6 +960,10 @@ abstract class Mixin extends InfoTransform { // assign to fields in some implementation class via an abstract // setter in the interface. localTyper.typed { + // println(lhs.symbol) + // println(lhs.symbol.owner.info.decls) + // println(needsExpandedSetterName(lhs.symbol)) + // util.trace("generating tree: ") { atPos(tree.pos) { Apply( Select( @@ -969,7 +973,7 @@ abstract class Mixin extends InfoTransform { needsExpandedSetterName(lhs.symbol))) setPos lhs.pos, List(rhs)) } - } + } //} case _ => tree } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 798a0f91af..9c82ffad1f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2140,7 +2140,11 @@ trait Typers { self: Analyzer => def apply(tp: Type): Type = tp match { case TypeRef(pre, sym, args) => if (sym.isAliasType && containsLocal(tp)) apply(tp.normalize) - else mapOver(tp) + else { + if (pre.isVolatile) + context.error(tree.pos, "Inferred type "+tree.tpe+" contains type selection from volatile type "+pre) + mapOver(tp) + } case _ => mapOver(tp) } diff --git a/src/compiler/scala/tools/nsc/util/SourceFile.scala b/src/compiler/scala/tools/nsc/util/SourceFile.scala index 4bda1e340b..7cddd24e54 100644 --- a/src/compiler/scala/tools/nsc/util/SourceFile.scala +++ b/src/compiler/scala/tools/nsc/util/SourceFile.scala @@ -61,13 +61,14 @@ class BatchSourceFile(val file : AbstractFile, _content : Array[Char]) extends S val content = _content // don't sweat it... override val length = content.length + override def identifier(pos : Position, compiler : scala.tools.nsc.Global) = pos match { - case OffsetPosition(source,offset) if source == this => - import java.lang.Character - var i = offset + 1 - while (i < content.length && - (compiler.syntaxAnalyzer.isOperatorPart(content(i)) || - compiler.syntaxAnalyzer.isIdentifierPart(content(i)))) i = i + 1 + case OffsetPosition(source,offset) if source == this => + import java.lang.Character + var i = offset + 1 + while (i < content.length && + (compiler.syntaxAnalyzer.isOperatorPart(content(i)) || + compiler.syntaxAnalyzer.isIdentifierPart(content(i)))) i = i + 1 assert(i > offset) if (i <= content.length && offset >= 0) @@ -76,8 +77,6 @@ class BatchSourceFile(val file : AbstractFile, _content : Array[Char]) extends S case _ => super.identifier(pos, compiler) } - - def isLineBreak(idx: Int) = if (idx >= content.length) false else if (!SourceFile.isLineBreak(content(idx))) false diff --git a/test/files/neg/volatile.check b/test/files/neg/volatile.check new file mode 100644 index 0000000000..b904284125 --- /dev/null +++ b/test/files/neg/volatile.check @@ -0,0 +1,7 @@ +volatile.scala:11: error: Inferred type C.this.D with C.this.E#T contains type selection from volatile type C.this.D with C.this.E + var sneak = { () => y.x } + ^ +volatile.scala:11: error: Inferred type () => C.this.D with C.this.E#T contains type selection from volatile type C.this.D with C.this.E + var sneak = { () => y.x } + ^ +two errors found diff --git a/test/files/neg/volatile.scala b/test/files/neg/volatile.scala new file mode 100644 index 0000000000..11f6eb539f --- /dev/null +++ b/test/files/neg/volatile.scala @@ -0,0 +1,24 @@ +object Test extends Application { + trait A + trait B extends A + + class C { + type D + trait E { type T >: B <: A; val x : T } + // This is currently correctly disallowed + // val y : (D with E)#T = y + val y : D with E = y + var sneak = { () => y.x } + sneak = { () => new B { } } + } + + class F extends C { + trait G + trait H { type T = G } + type D = H + def frob(arg : G) : G = arg + frob(sneak()) + } + + new F +} |