Skip to content

Commit 55e00c0

Browse files
authored
Merge pull request #8523 from dotty-staging/add-prototye-conversion-with-dependent-functions-suport
Add prototype conversion with dependent functions support
2 parents 16b74d8 + fa76c6f commit 55e00c0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package scala
2+
3+
4+
object ConversionFunction {
5+
6+
opaque type ConversionFunction[+F <: Nothing => Any] = F
7+
8+
def apply[F <: Nothing => Any](f: F): ConversionFunction[F] = f
9+
def get[F <: Nothing => Any](using f: ConversionFunction[F]): F = f
10+
11+
}
12+
13+
type ConversionFunction[+F <: Nothing => Any] =
14+
ConversionFunction.ConversionFunction[F]
15+
16+
object Test {
17+
18+
{
19+
given ConversionFunction[Int => String] = ConversionFunction(_.toString)
20+
// val a: String = 3
21+
val a: String = ConversionFunction.get[3 => String].apply(3)
22+
}
23+
24+
trait X {
25+
type T
26+
def t: T
27+
}
28+
val x: X = ???
29+
30+
{
31+
given ConversionFunction[(x: X) => x.T] = ConversionFunction((x: X) => x.t)
32+
// val a: x.T = x
33+
val a: x.T = ConversionFunction.get[(x: X) => x.T].apply(x)
34+
}
35+
36+
{
37+
given ConversionFunction[(x: X) => x.T] = ConversionFunction(_.t)
38+
// val a: x.T = x
39+
val a: x.T = ConversionFunction.get[(x: X) => x.T].apply(x)
40+
}
41+
42+
}

0 commit comments

Comments
 (0)