diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-06-20 08:19:40 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-06-20 08:19:40 +0000 |
commit | 0e170e4b695adafb3f3d5823026ccf8d10047be3 (patch) | |
tree | 58dd5a4ca9e73602222733720c5ead9612e0282e /test/files/run | |
parent | 60810d5c03ef614497d3a8ba5ad23d44e48194a8 (diff) | |
download | scala-0e170e4b695adafb3f3d5823026ccf8d10047be3.tar.gz scala-0e170e4b695adafb3f3d5823026ccf8d10047be3.tar.bz2 scala-0e170e4b695adafb3f3d5823026ccf8d10047be3.zip |
improvements to names / defaults (implicits, ty...
improvements to names / defaults (implicits, type of defaults, #2064,
...)
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/names-defaults.check | 9 | ||||
-rw-r--r-- | test/files/run/names-defaults.scala | 43 |
2 files changed, 51 insertions, 1 deletions
diff --git a/test/files/run/names-defaults.check b/test/files/run/names-defaults.check index 07a7d7d1be..e8c088fe7a 100644 --- a/test/files/run/names-defaults.check +++ b/test/files/run/names-defaults.check @@ -97,4 +97,11 @@ slkdfj1 lskfdjlk 11 2 -20
\ No newline at end of file +20 +10 +jaa +kldfj110101 +klfj1 +blublu1 +my text +List(1, 2) diff --git a/test/files/run/names-defaults.scala b/test/files/run/names-defaults.scala index 6ec391af2f..3efefc9e71 100644 --- a/test/files/run/names-defaults.scala +++ b/test/files/run/names-defaults.scala @@ -198,6 +198,40 @@ object Test extends Application { new B4() new B5() + // no re-naming of parameters which are free in a closure of the body (lambdalift) + println(test6(10)()) + test7("jaa") + + // implicits + defaults + { + implicit val implInt = 10101 + println(test8()) + } + + println(test9) + + { + implicit val implString = "blublu" + println(test9) + } + + + // result type of default getters: parameter type, except if this one mentions any type + // parameter, in which case the result type is inferred. examples: + + // result type of default getter is "String => String". if it were infered, the compiler + // would put "Nothing => Nothing", which is useless + def transform(s: String, f: String => String = identity _) = f(s) + println(transform("my text")) + + // result type of the default getter is inferred (parameter type mentions type parameter T) + def test10[T](x: List[T] = List(1,2)) = x + println(test10()) + + // some complicated type which mentions T + def test11[T[P]](x: T[T[List[T[X forSome { type X }]]]] = List(1,2)) = x + // (cannot call f using the default, List(1,2) doesn't match the param type) + // DEFINITIONS def test1(a: Int, b: String) = println(a +": "+ b) @@ -210,6 +244,11 @@ object Test extends Application { inner(c = "/") } def test5(argName: Unit) = println("test5") + def test6(x: Int) = { () => x } + def test7(s: String) = List(1).foreach(_ => println(s)) + + def test8(x: Int = 1)(implicit y: Int, z: String = "kldfj") = z + x + y + def test9(implicit x: Int = 1, z: String = "klfj") = z + x } @@ -288,3 +327,7 @@ class B4 extends A5(10)() { class B5 extends A5(y = 20, x = 2)() { println(y) } + +// overriding default can be less specific (but has to conform to argument type!) +class A6 { def foo(a: Object = "dlkf") = 0 } +class B6 extends A6 { override def foo(a: Object = new Object) = 1 } |