summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/names-defaults.check9
-rw-r--r--test/files/run/names-defaults.scala43
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 }