summaryrefslogtreecommitdiff
path: root/test/files/run/names-defaults.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-06-20 08:19:40 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-06-20 08:19:40 +0000
commit0e170e4b695adafb3f3d5823026ccf8d10047be3 (patch)
tree58dd5a4ca9e73602222733720c5ead9612e0282e /test/files/run/names-defaults.scala
parent60810d5c03ef614497d3a8ba5ad23d44e48194a8 (diff)
downloadscala-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/names-defaults.scala')
-rw-r--r--test/files/run/names-defaults.scala43
1 files changed, 43 insertions, 0 deletions
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 }