summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-03-17 16:17:04 -0700
committerJason Zaugg <jzaugg@gmail.com>2015-03-17 16:17:04 -0700
commit79c053738b8907e461e5087f63d247a64271509a (patch)
tree5f29c54b7b61e05346ad28c77e01e0d0b96ab07e /test
parentfa33395a25c87115c910e8d4a4124aee6134062b (diff)
downloadscala-79c053738b8907e461e5087f63d247a64271509a.tar.gz
scala-79c053738b8907e461e5087f63d247a64271509a.tar.bz2
scala-79c053738b8907e461e5087f63d247a64271509a.zip
SI-9223 By-name constructor params should not be aliased
Usually, the compiler tries avoids creating a field in a subclass for a constructor parameter that is known to be stored in a field in one of its superclasses. However, in the enclosed test `run/t9223.scala`, this mechanism confuses `=> A` with `A`, which results in a runtime `ClassCastException`. This commit avoids using param aliases for by-name parameters. I have also added a test for something close the opposite case, where the subclass has a strict parameter and the superclass has a by-name parameter. This was working correctly before this patch.
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t9223.scala8
-rw-r--r--test/files/run/t9223b.scala8
2 files changed, 16 insertions, 0 deletions
diff --git a/test/files/run/t9223.scala b/test/files/run/t9223.scala
new file mode 100644
index 0000000000..78767b158d
--- /dev/null
+++ b/test/files/run/t9223.scala
@@ -0,0 +1,8 @@
+class X(val x: String)
+class Y(y: => String) extends X(y) { def f = y }
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ assert(new Y("hi").f == "hi")
+ }
+}
diff --git a/test/files/run/t9223b.scala b/test/files/run/t9223b.scala
new file mode 100644
index 0000000000..2afc7ddfe0
--- /dev/null
+++ b/test/files/run/t9223b.scala
@@ -0,0 +1,8 @@
+class X(x: => String) { def xx = x }
+class Y(y: String) extends X(y) { def f = y }
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ assert(new Y("hi").f == "hi")
+ }
+}