Skip to content

Type inference issue in presence of implicits and path-dependent types #10161

Closed
@julienrf

Description

@julienrf

Minimized code

object Incompat2 {
  trait Context { type Out }

  object Context {
    def foo(implicit ctx: Context): Option[ctx.Out] = ???

    def bar(implicit ctx: Context): (Option[ctx.Out], String) = (foo, "foo")
  }
}

Output

7 |    def bar(implicit ctx: Context): (Option[ctx.Out], String) = (foo, "foo")
  |                                                                ^^^^^^^^^^^^
  |                                       Found:    (Option[Any], String)
  |                                       Required: (Option[ctx.Out], String)

Expectation

The code compiles.

It does compile if we pass the implicit parameter explicitly, though:

object Incompat2 {
  trait Context { type Out }

  object Context {
    def foo(implicit ctx: Context): Option[ctx.Out] = ???

    def bar(implicit ctx: Context): (Option[ctx.Out], String) = (foo(ctx), "foo") // note: foo(ctx)
  }
}

Probably a similar test case can be found in https://github.com/mlachkar/scala-migrat3/pull/22

Maybe similar issues: #8991, #8882

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions