summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala4
-rw-r--r--test/files/neg/bug4419.check4
-rw-r--r--test/files/neg/bug4419.scala3
-rw-r--r--test/files/pos/widen-existential.scala3
4 files changed, 12 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 8f20f2a120..bc6a468538 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -614,7 +614,7 @@ trait Namers { self: Analyzer =>
* modifier is the present means of signaling that a constant
* value should not be widened, so it has a use even in situations
* whether it is otherwise redundant (such as in a singleton.)
- * Locally defined symbols are also excluded from widening.
+ * Method-defined locals are also excluded from widening.
*/
private def widenIfNecessary(sym: Symbol, tpe: Type, pt: Type): Type = {
val getter =
@@ -636,7 +636,7 @@ trait Namers { self: Analyzer =>
if ((sym.isVariable || sym.isMethod && !sym.hasAccessorFlag))
if (tpe2 <:< pt) tpe2 else tpe1
else if (isHidden(tpe)) tpe2
- else if (sym.isFinal || sym.isLocal) tpe
+ else if (sym.isFinal || sym.owner.isMethod) tpe
else tpe1
}
diff --git a/test/files/neg/bug4419.check b/test/files/neg/bug4419.check
new file mode 100644
index 0000000000..488be9a591
--- /dev/null
+++ b/test/files/neg/bug4419.check
@@ -0,0 +1,4 @@
+bug4419.scala:2: error: forward reference extends over definition of value b
+ { val b = a; val a = 1 }
+ ^
+one error found
diff --git a/test/files/neg/bug4419.scala b/test/files/neg/bug4419.scala
new file mode 100644
index 0000000000..38a34be489
--- /dev/null
+++ b/test/files/neg/bug4419.scala
@@ -0,0 +1,3 @@
+class A {
+ { val b = a; val a = 1 }
+} \ No newline at end of file
diff --git a/test/files/pos/widen-existential.scala b/test/files/pos/widen-existential.scala
new file mode 100644
index 0000000000..90a62e461b
--- /dev/null
+++ b/test/files/pos/widen-existential.scala
@@ -0,0 +1,3 @@
+class A {
+ { val x = classOf[List[_]] }
+} \ No newline at end of file