Skip to content

Still can't find implicit of refined type when path-dependent type is used #8882

Open
@DmytroMitin

Description

@DmytroMitin

#8825 is resolved but if we rewrite code slightly the problem remains.

Minimized code

In Dotty 0.25.0-bin-20200504-11760ea-NIGHTLY with

  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 {
    given hnilLength as Length[HNil] {
      override type Out = Zero
    }
    given hconsLength[H, T <: HList](using length: Length[T]) as Length[HCons[H, T]] {
      override type Out = Succ[length.Out]
    } // (*)
//    given hconsLength[H, T <: HList, Out0 <: Nat](using length: Length[T] {type Out = Out0}) as Length[HCons[H, T]] {
//      override type Out = Succ[Out0]
//    } // (**)
  }

Output

summon[Length[HCons[Int, HNil]] { type Out = One}] doesn't compile

[error] -- Error: ...
[error] .. |  summon[Length[HCons[Int, HNil]] { type Out = One}]
[error]    |                                                    ^
[error]    |no implicit argument of type App.Length[App.HCons[Int, App.HNil]]{Out = App.One} was found for parameter x of method summon in object DottyPredef

Expectation

summon[Length[HCons[Int, HNil]] { type Out = One}] should compile.

If we replace line (*) with (**) then summon[Length[HCons[Int, HNil]] { type Out = One}] compiles.

If we resolve implicits manually, summon[Length[HCons[Int, HNil]] { type Out = One}](using Length.hconsLength[Int, HNil](using Length.hnilLength)) doesn't compile with (*) either

[error] -- [E007] Type Mismatch Error: ...
[error] .. |  summon[Length[HCons[Int, HNil]] { type Out = One}](using Length.hconsLength[Int, HNil](using Length.hnilLength))
[error]    |                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |       Found:    App.Length.hconsLength[Int, App.HNil]
[error]    |       Required: App.Length[App.HCons[Int, App.HNil]]{Out = App.One}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions