Skip to content

Scala 2.13 regression: type param affecting overload #12663

Closed
@japgolly

Description

@japgolly

Compiler version

3.0.0

Minimized code (ver 1)

final class HookComponentBuilder[Ctx, CtxFn[_]] {
  def asd[A](f: Ctx => A): A = ???
  def asd[A](f: CtxFn[A]): A = ???
}

object HookCtx {
  case class P1[P, H1](props: P, hook1: H1)
}

object HookCtxFn {
  sealed trait P1[P, H1] { type Fn[A] = (P, H1) => A }
}

object Test {
  val b: HookComponentBuilder[HookCtx.P1[String, Int], HookCtxFn.P1[String, Int]#Fn] = ???

  b.asd($ => $.props.length + $.hook1)
  b.asd((props, hook1) => props.length + hook1)
}

Minimized code (ver 2)

Changing HookCtxFn.P1 to a type lambda...

final class HookComponentBuilder[Ctx, CtxFn[_]] {
  def asd[A](f: Ctx => A): A = ???
  def asd[A](f: CtxFn[A]): A = ???
}

object HookCtx {
  case class P1[P, H1](props: P, hook1: H1)
}

object HookCtxFn {
  type P1[P, H1] = [A] =>> (P, H1) => A
}

object Test {
  val b: HookComponentBuilder[HookCtx.P1[String, Int], HookCtxFn.P1[String, Int]] = ???

  b.asd($ => $.props.length + $.hook1)
  b.asd((props, hook1) => props.length + hook1)
}

Output

[error] 18 |  b.asd((props, hook1) => props.length + hook1)
[error]    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |        Wrong number of parameters, expected: 1

Expectation

It should compile. It does with Scala 2.13

Workaround

Inlining HookCtxFn.P1 makes it work.

final class HookComponentBuilder[Ctx, CtxFn[_]] {
  def asd[A](f: Ctx => A): A = ???
  def asd[A](f: CtxFn[A]): A = ???
}

object HookCtx {
  case class P1[P, H1](props: P, hook1: H1)
}

object Test {
  val b: HookComponentBuilder[HookCtx.P1[String, Int], [A] =>> (String, Int) => A] = ???

  b.asd($ => $.props.length + $.hook1)
  b.asd((props, hook1) => props.length + hook1)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogNo work planned on this by the core team for the time being.itype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions