forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiate argument type vars before implicit search (scala#19096)
- Loading branch information
1 parent
1716bcd
commit cce2933
Showing
4 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
trait Animal | ||
class Dog extends Animal | ||
|
||
trait Ev[T] | ||
|
||
given Ev[Dog] = ??? | ||
given Ev[Animal] = ??? | ||
given[T: Ev]: Ev[Set[T]] = ??? | ||
|
||
def f[T: Ev](v: T): Unit = ??? | ||
|
||
def main = | ||
val s = Set(new Dog) | ||
f(s) // Ok | ||
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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
trait Nat | ||
case object Z extends Nat | ||
case class S[N <: Nat](pred: N) extends Nat | ||
|
||
type Z = Z.type | ||
given zero: Z = Z | ||
given succ[N <: Nat](using n: N): S[N] = S(n) | ||
|
||
case class Sum[N <: Nat, M <: Nat, R <: Nat](result: R) | ||
|
||
given sumZ[N <: Nat](using n: N): Sum[Z, N, N] = Sum(n) | ||
given sumS[N <: Nat, M <: Nat, R <: Nat]( | ||
using sum: Sum[N, M, R] | ||
): Sum[S[N], M, S[R]] = Sum(S(sum.result)) | ||
|
||
def add[N <: Nat, M <: Nat, R <: Nat](n: N, m: M)( | ||
using sum: Sum[N, M, R] | ||
): R = sum.result | ||
|
||
case class Prod[N <: Nat, M <: Nat, R <: Nat](result: R) | ||
|
||
|
||
@main def Test: Unit = | ||
|
||
val n1: S[Z] = add(Z, S(Z)) | ||
summon[n1.type <:< S[Z]] // OK | ||
|
||
val n3: S[S[S[Z]]] = add(S(S(Z)), S(Z)) | ||
summon[n3.type <:< S[S[S[Z]]]] // Ok | ||
|
||
val m3_2 = add(S(Z), S(S(Z))) | ||
summon[m3_2.type <:< S[S[S[Z]]]] // Error before changes: Cannot prove that (m3_2 : S[S[Nat]]) <:< S[S[S[Z]]] | ||
|
||
val m4_2 = add(S(Z), S(S(S(Z)))) | ||
summon[m4_2.type <:< S[S[S[S[Z]]]]] | ||
|
||
|