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.
Merge pull request scala#8824 from dotty-staging/fix-#8802
Fix scala#8802: Use wildcards for result type approximation of implicits
- Loading branch information
Showing
3 changed files
with
50 additions
and
8 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 Foo[A, B] { | ||
type Out | ||
} | ||
|
||
object Test { | ||
|
||
type Bar[A] | ||
|
||
def unit: Bar[Unit] = ??? | ||
def product[A, B](fst: Bar[A], snd: Bar[B])(implicit foo: Foo[A, B]): Bar[foo.Out] = ??? | ||
|
||
implicit def foo[A]: Foo[A, Unit] { type Out = A } = ??? | ||
|
||
def check[A](bar: Bar[A])(a: A): Unit = {} | ||
|
||
check(product(unit, unit))(()) // error | ||
} |
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,24 @@ | ||
sealed trait Nat | ||
case class Succ[N <: Nat](n: N) extends Nat | ||
case object Zero extends Nat | ||
type Zero = Zero.type | ||
type One = Succ[Zero] | ||
|
||
sealed trait HList | ||
case class HCons[+H, +T <: HList](head: H, tail: T) extends HList | ||
case object HNil extends HList | ||
type HNil = HNil.type | ||
|
||
trait Length[L <: HList] { | ||
type Out <: Nat | ||
} | ||
object Length { | ||
type Aux[L <: HList, Out0 <: Nat] = Length[L] { type Out = Out0 } | ||
def instance[L <: HList, Out0 <: Nat]: Aux[L, Out0] = new Length[L] { type Out = Out0 } | ||
|
||
given hnilLength as Aux[HNil, Zero] = instance | ||
given hconsLength[H, T <: HList] (using length: Length[T]) as Aux[HCons[H, T], Succ[length.Out]] = instance // (*) | ||
//given hconsLength[H, T <: HList, N <: Nat] (using length: Aux[T, N]) as Aux[HCons[H, T], Succ[N]] = instance // (**) | ||
} | ||
|
||
val test = summon[Length.Aux[HCons[Int, HNil], One]] |