Skip to content

Commit 1df7d83

Browse files
Add test from i7586
1 parent 67ae357 commit 1df7d83

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

tests/pos/i18578.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def f[T: Ev](v: T): Unit = ???
1212

1313
def main =
1414
val s = Set(new Dog)
15-
// f(s) // WORKS
16-
f(Set(new Dog)) // FAILS
17-
// instantiates to
15+
f(s) // Ok
16+
f(Set(new Dog)) // Error before changes: Ambiguous given instances: both given instance given_Ev_Dog and given instance given_Ev_Animal match type Ev[T]
17+

tests/pos/i7586.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
trait Nat
3+
case object Z extends Nat
4+
case class S[N <: Nat](pred: N) extends Nat
5+
6+
type Z = Z.type
7+
given zero: Z = Z
8+
given succ[N <: Nat](using n: N): S[N] = S(n)
9+
10+
case class Sum[N <: Nat, M <: Nat, R <: Nat](result: R)
11+
12+
given sumZ[N <: Nat](using n: N): Sum[Z, N, N] = Sum(n)
13+
given sumS[N <: Nat, M <: Nat, R <: Nat](
14+
using sum: Sum[N, M, R]
15+
): Sum[S[N], M, S[R]] = Sum(S(sum.result))
16+
17+
def add[N <: Nat, M <: Nat, R <: Nat](n: N, m: M)(
18+
using sum: Sum[N, M, R]
19+
): R = sum.result
20+
21+
case class Prod[N <: Nat, M <: Nat, R <: Nat](result: R)
22+
23+
24+
@main def Test: Unit =
25+
26+
val n1: S[Z] = add(Z, S(Z))
27+
summon[n1.type <:< S[Z]] // OK
28+
29+
val n3: S[S[S[Z]]] = add(S(S(Z)), S(Z))
30+
summon[n3.type <:< S[S[S[Z]]]] // Ok
31+
32+
val m3_2 = add(S(Z), S(S(Z)))
33+
summon[m3_2.type <:< S[S[S[Z]]]] // Error before changes: Cannot prove that (m3_2 : S[S[Nat]]) <:< S[S[S[Z]]]
34+
35+
val m4_2 = add(S(Z), S(S(S(Z))))
36+
summon[m4_2.type <:< S[S[S[S[Z]]]]]
37+
38+

0 commit comments

Comments
 (0)