aboutsummaryrefslogtreecommitdiff
path: root/tests/run/implicitFuns.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-12-05 10:34:58 +0100
committerMartin Odersky <odersky@gmail.com>2016-12-17 18:34:27 +0100
commitbcc80ad1343a3ed01bef55f494d9658cf02226c6 (patch)
tree5fb2feecdf0df524128c72d14a6402fd6c547291 /tests/run/implicitFuns.scala
parent0336785a2280a4a1e51e739e9aac3d5015f7c16f (diff)
downloaddotty-bcc80ad1343a3ed01bef55f494d9658cf02226c6.tar.gz
dotty-bcc80ad1343a3ed01bef55f494d9658cf02226c6.tar.bz2
dotty-bcc80ad1343a3ed01bef55f494d9658cf02226c6.zip
Create implicit closures to math expected implicit functions
When the expected type is an implicit function, create an implicit closure to match it.
Diffstat (limited to 'tests/run/implicitFuns.scala')
-rw-r--r--tests/run/implicitFuns.scala55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/run/implicitFuns.scala b/tests/run/implicitFuns.scala
new file mode 100644
index 000000000..79f0632d2
--- /dev/null
+++ b/tests/run/implicitFuns.scala
@@ -0,0 +1,55 @@
+object Test {
+ def main(args: Array[String]) = {
+
+ implicit val world: String = "world!"
+
+ val i1 = (implicit (s: String) => s.length > 2)
+ val i2 = {implicit (s: String) => s.length > 2}
+
+ assert(i1)
+ assert(i2)
+
+ val x: implicit String => Boolean = { implicit (s: String) => s.length > 2 }
+
+ val xx: implicit (String, Int) => Int = implicit (x: String, y: Int) => x.length + y
+
+ val y: String => Boolean = x
+
+ object nested {
+ implicit val empty: String = ""
+ assert(!x)
+ }
+
+ val yy: (String, Int) => Any = xx
+
+ val z1: implicit String => Boolean = implicitly[String].length >= 2
+ assert(z1)
+
+ type StringlyBool = implicit String => Boolean
+
+ val z2: StringlyBool = implicitly[String].length >= 2
+ assert(z2)
+
+ type Stringly[T] = implicit String => T
+
+ val z3: Stringly[Boolean] = implicitly[String].length >= 2
+ assert(z3)
+
+ type GenericImplicit[X] = implicit X => Boolean
+
+ val z4: GenericImplicit[String] = implicitly[String].length >= 2
+ assert(z4)
+
+ val b = x("hello")
+
+ val b1: Boolean = b
+
+ val bi = x
+
+ val bi1: Boolean = bi
+
+ val c = xx("hh", 22)
+
+ val c1: Int = c
+ }
+}