summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-05-30 15:36:57 +0000
committerMartin Odersky <odersky@gmail.com>2007-05-30 15:36:57 +0000
commit1cc6a768e075c0d764ae0625598b5d352ec1b4f2 (patch)
tree120dc52ad301cf2ed19296488723e6c527cde961
parent2dcbfa7d08d1063757713d77ff39557a89be3014 (diff)
downloadscala-1cc6a768e075c0d764ae0625598b5d352ec1b4f2.tar.gz
scala-1cc6a768e075c0d764ae0625598b5d352ec1b4f2.tar.bz2
scala-1cc6a768e075c0d764ae0625598b5d352ec1b4f2.zip
fixed bug 1123
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala21
-rw-r--r--test/files/pos/bug1034.scala6
-rw-r--r--test/files/pos/bug1075.scala17
-rw-r--r--test/files/pos/bug1119.scala10
-rw-r--r--test/files/pos/bug1123.scala11
-rw-r--r--test/files/pos/caseaccs.scala11
-rwxr-xr-xtest/files/pos/itay.scala4
8 files changed, 74 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index e1ba10a064..aba9a20229 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -365,7 +365,7 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter
else atPos(tree.pos)(outerPath(outerValue, currentClass.outerClass, sym)) // (5)
case Select(qual, name) =>
- if (currentClass != sym.owner && currentClass != sym.moduleClass) // (3)
+ if (currentClass != sym.owner/* && currentClass != sym.moduleClass*/) // (3)
sym.makeNotPrivate(sym.owner)
val qsym = qual.tpe.widen.symbol
if ((sym hasFlag PROTECTED) && //(4)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 93de2f5cb1..256244313a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -444,6 +444,13 @@ trait Typers requires Analyzer {
typer1
} else this
+ /** Does the context of tree `tree' require a stable type?
+ */
+ private def isStableContext(tree: Tree, mode: int, pt: Type) =
+ pt.isStable ||
+ (mode & QUALmode) != 0 && !tree.symbol.isConstant ||
+ pt.symbol.isAbstractType && pt.bounds.lo.isStable && !(tree.tpe <:< pt)
+
/** <p>
* Post-process an identifier or selection node, performing the following:
* </p>
@@ -470,8 +477,8 @@ trait Typers requires Analyzer {
errorTree(tree, sym+" is not a value")
} else {
if (sym.isStable && pre.isStable && tree.tpe.symbol != ByNameParamClass &&
- (pt.isStable || (mode & QUALmode) != 0 && !sym.isConstant ||
- sym.isModule && !sym.isMethod)) tree.setType(singleType(pre, sym))
+ (isStableContext(tree, mode, pt) || sym.isModule && !sym.isMethod))
+ tree.setType(singleType(pre, sym))
else tree
}
}
@@ -489,8 +496,8 @@ trait Typers requires Analyzer {
case _ => NoPrefix
}
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)))
+ (isStableContext(tree, mode, pt) || sym.isModule))
+ tree.setType(MethodType(List(), singleType(pre, sym)))
else tree
}
@@ -2131,9 +2138,9 @@ trait Typers requires Analyzer {
}
if (clazz == NoSymbol) setError(tree)
else {
- val owntype = if (pt.isStable || (mode & QUALmode) != 0) selftype
- else selftype.singleDeref
- tree setSymbol clazz setType owntype
+ tree setSymbol clazz setType selftype.singleDeref
+ if (isStableContext(tree, mode, pt)) tree setType selftype
+ tree
}
}
diff --git a/test/files/pos/bug1034.scala b/test/files/pos/bug1034.scala
new file mode 100644
index 0000000000..d6c1591bd2
--- /dev/null
+++ b/test/files/pos/bug1034.scala
@@ -0,0 +1,6 @@
+object Terminal {
+ def apply[a] : a => unit = { a => () }
+ val i0 = Terminal.apply[int]
+ val i1 = (Terminal)[int]
+ val i2 = Terminal[int]
+}
diff --git a/test/files/pos/bug1075.scala b/test/files/pos/bug1075.scala
new file mode 100644
index 0000000000..936ef72272
--- /dev/null
+++ b/test/files/pos/bug1075.scala
@@ -0,0 +1,17 @@
+class Directory(var dir_ : String)
+{
+ if (!dir_.startsWith("/")) {
+ throw new RuntimeException("Invalid directory")
+ }
+ dir_ = dir_.replaceAll("/{2,}", "/")
+
+ def this(serialized : Array[byte]) = {
+ this(new String(serialized, "UTF-8"))
+ }
+
+ def dir = dir_
+}
+
+object Test extends Directory("/bab/dkkd//dkkdkd//kdkdk") with Application {
+ println(dir)
+}
diff --git a/test/files/pos/bug1119.scala b/test/files/pos/bug1119.scala
new file mode 100644
index 0000000000..8b36877c49
--- /dev/null
+++ b/test/files/pos/bug1119.scala
@@ -0,0 +1,10 @@
+trait B
+{
+ type T >: this.type <: B
+
+
+ // compile-time check: have we achieved our objective?
+ def test: T = this
+}
+
+
diff --git a/test/files/pos/bug1123.scala b/test/files/pos/bug1123.scala
new file mode 100644
index 0000000000..3812fa3eb3
--- /dev/null
+++ b/test/files/pos/bug1123.scala
@@ -0,0 +1,11 @@
+
+package test;
+object Test {
+ class Editor {
+ private object extraListener {
+ def h : AnyRef = extraListener
+ }
+ def f = extraListener.h
+ }
+ def main(args : Array[String]) : Unit = (new Editor).f
+}
diff --git a/test/files/pos/caseaccs.scala b/test/files/pos/caseaccs.scala
new file mode 100644
index 0000000000..2668127fc9
--- /dev/null
+++ b/test/files/pos/caseaccs.scala
@@ -0,0 +1,11 @@
+class Test {
+ case class Foo(x: int, private var y: int)
+}
+
+object Test {
+ val test = new Test
+ val x = test.Foo(1, 2)
+ x match {
+ case test.Foo(x, y) => println(x); println(y)
+ }
+}
diff --git a/test/files/pos/itay.scala b/test/files/pos/itay.scala
new file mode 100755
index 0000000000..9a97ded988
--- /dev/null
+++ b/test/files/pos/itay.scala
@@ -0,0 +1,4 @@
+abstract class Message[+A]
+
+trait InPort [+T <: Message[V], +V]
+