diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-06-15 15:03:20 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-06-15 15:03:20 +0000 |
commit | 7337db9c59daeac26e81e22cfea4f7d8b43a0747 (patch) | |
tree | fdf3fa7868907040432296e889f8030010c7b3e6 /test/files | |
parent | a907772ff59f7150637494f46b60665ca6e21163 (diff) | |
download | scala-7337db9c59daeac26e81e22cfea4f7d8b43a0747.tar.gz scala-7337db9c59daeac26e81e22cfea4f7d8b43a0747.tar.bz2 scala-7337db9c59daeac26e81e22cfea4f7d8b43a0747.zip |
allow using named / default arguments in self- ...
allow using named / default arguments in self- and super constructor
calls. fixes #2050 and #2052.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/names-defaults-neg.check | 16 | ||||
-rw-r--r-- | test/files/neg/names-defaults-neg.scala | 19 | ||||
-rw-r--r-- | test/files/run/names-defaults.check | 7 | ||||
-rw-r--r-- | test/files/run/names-defaults.scala | 39 |
4 files changed, 47 insertions, 34 deletions
diff --git a/test/files/neg/names-defaults-neg.check b/test/files/neg/names-defaults-neg.check index d4331ab63f..b208157c6a 100644 --- a/test/files/neg/names-defaults-neg.check +++ b/test/files/neg/names-defaults-neg.check @@ -85,21 +85,9 @@ names-defaults-neg.scala:88: error: type mismatch; names-defaults-neg.scala:88: error: multiple overloaded alternatives of method bar define default arguments def bar(i: Int = 129083) = i ^ -names-defaults-neg.scala:93: error: using named or default arguments in a super constructor call is not allowed -class B1 extends A1(10) - ^ -names-defaults-neg.scala:94: error: using named or default arguments in a super constructor call is not allowed -class B2 extends A1(y = 20, x = 2) - ^ -names-defaults-neg.scala:99: error: using named or default arguments in a self constructor call is not allowed - this(y = 10, x = a.toString()) - ^ -names-defaults-neg.scala:105: error: using named or default arguments in a self constructor call is not allowed - this(sep + b + sep) - ^ -names-defaults-neg.scala:112: error: type mismatch; +names-defaults-neg.scala:95: error: type mismatch; found : java.lang.Object required: java.lang.String class B5 extends A5 { override def foo(a: Object = new Object) = 1 } ^ -26 errors found
\ No newline at end of file +22 errors found
\ No newline at end of file diff --git a/test/files/neg/names-defaults-neg.scala b/test/files/neg/names-defaults-neg.scala index 29db82924c..68cdcf782f 100644 --- a/test/files/neg/names-defaults-neg.scala +++ b/test/files/neg/names-defaults-neg.scala @@ -88,25 +88,8 @@ class C extends B { def bar(i: Int = 129083) = i } -// using names / defaults in super constructor call not allowed -class A1(x: Int, y: Int = 2) -class B1 extends A1(10) -class B2 extends A1(y = 20, x = 2) - -// using names / defaults in self constructor call not allowed -class A2(x: String, y: Int = 10) { - def this(a: Object) { - this(y = 10, x = a.toString()) - println(x) - } -} -class A3(x: String, y: Int = 11) { - def this(b: Double, sep: String) { - this(sep + b + sep) - } -} - case class Fact(a: Int, b: String)(c: Int*) +// overriding default must have same type class A5 { def foo(a: Object = "dlkf") = 0 } class B5 extends A5 { override def foo(a: Object = new Object) = 1 } diff --git a/test/files/run/names-defaults.check b/test/files/run/names-defaults.check index 3fed6e601a..07a7d7d1be 100644 --- a/test/files/run/names-defaults.check +++ b/test/files/run/names-defaults.check @@ -92,4 +92,9 @@ test5 2 test5 3 -slkdfj1
\ No newline at end of file +slkdfj1 +1 +lskfdjlk +11 +2 +20
\ No newline at end of file diff --git a/test/files/run/names-defaults.scala b/test/files/run/names-defaults.scala index c016a98e1a..6ec391af2f 100644 --- a/test/files/run/names-defaults.scala +++ b/test/files/run/names-defaults.scala @@ -183,10 +183,21 @@ object Test extends Application { // bug #2057 - class O { class I(x: Int = 1) } + class O { class I(val x: Int = 1) } class U extends O { val f = new I() } + val u1 = new U + println(u1.f.x) + // names / defaults in self constructor call + new A3("lskfdjlk") + new A4(1.23, ",") + + + // names / defaults in super constructor call + new B4() + new B5() + // DEFINITIONS def test1(a: Int, b: String) = println(a +": "+ b) @@ -251,3 +262,29 @@ class A2 { } class C2 } + + + +// using names / defaults in self constructor call +class A3(x: String, y: Int = 10) { + def this(a: Object) { + this(y = 10, x = a.toString()) + println(x) + } +} +class A4(x: String, y: Int = 11) { + def this(b: Double, sep: String) { + this(sep + b + sep) + println(y) + } +} + + +// using names / defaults in super constructor call +class A5(x: Int, val y: Int = 2)(z: Int = x + y) +class B4 extends A5(10)() { + println(y) +} +class B5 extends A5(y = 20, x = 2)() { + println(y) +} |