From fa76c6fcb871b01b6f7cacb0d86a1b43190e0e56 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 12 Mar 2020 07:31:23 +0100 Subject: [PATCH] Add prototype conversion with dependent functions support --- tests/pos/conversion-function-prototype.scala | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/pos/conversion-function-prototype.scala diff --git a/tests/pos/conversion-function-prototype.scala b/tests/pos/conversion-function-prototype.scala new file mode 100644 index 000000000000..863a136e5a46 --- /dev/null +++ b/tests/pos/conversion-function-prototype.scala @@ -0,0 +1,42 @@ +package scala + + +object ConversionFunction { + + opaque type ConversionFunction[+F <: Nothing => Any] = F + + def apply[F <: Nothing => Any](f: F): ConversionFunction[F] = f + def get[F <: Nothing => Any](using f: ConversionFunction[F]): F = f + +} + +type ConversionFunction[+F <: Nothing => Any] = + ConversionFunction.ConversionFunction[F] + +object Test { + + { + given ConversionFunction[Int => String] = ConversionFunction(_.toString) + // val a: String = 3 + val a: String = ConversionFunction.get[3 => String].apply(3) + } + + trait X { + type T + def t: T + } + val x: X = ??? + + { + given ConversionFunction[(x: X) => x.T] = ConversionFunction((x: X) => x.t) + // val a: x.T = x + val a: x.T = ConversionFunction.get[(x: X) => x.T].apply(x) + } + + { + given ConversionFunction[(x: X) => x.T] = ConversionFunction(_.t) + // val a: x.T = x + val a: x.T = ConversionFunction.get[(x: X) => x.T].apply(x) + } + +}