question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scala 2.13 regression: type param affecting overload

See original GitHub issue

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)
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Jun 5, 2021

Thanks for the minimization! I will take another look.

1reaction
japgollycommented, Jun 2, 2021

Also did a quick test to see if all 4 representations are identical. They are:

object Test2 {
  sealed trait Scala2TL { type F[Z] = (String, Int) => Z }
  type Scala3TL = [Z] =>> (String, Int) => Z

  var b1: Builder[[Z] =>> (String, Int) => Z            ] = ???
  var b2: Builder[Scala2TL#F                            ] = ???
  var b3: Builder[Scala3TL                              ] = ???
  var b4: Builder[({ type F[Z] = (String, Int) => Z })#F] = ???

  b1 = b1
  b1 = b2
  b1 = b3
  b1 = b4

  b2 = b1
  b2 = b2
  b2 = b3
  b2 = b4

  b3 = b1
  b3 = b2
  b3 = b3
  b3 = b4

  b4 = b1
  b4 = b2
  b4 = b3
  b4 = b4

  // no errors. good.
}

So this must be just a .dealias needed somewhere in overload resolution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change in behavior in 2.13 for implicit overloads · Issue #11662
This code compiles on Scala 2.10, 2.11, and 2.12: class Foo(xs: ... match argument types (List[String]) and expected result type Foo.
Read more >
Changes in Overload Resolution - Scala 3 - EPFL
Overload resolution in Scala 3 improves on Scala 2 in three ways. First, it takes all argument lists into account instead of just...
Read more >
sbt Reference Manual — Combined Pages
Compiles and runs all tests. console, Starts the Scala interpreter with a classpath including the compiled sources and all dependencies. To return to...
Read more >
scala - Why "avoid method overloading"? - Stack Overflow
There is a greater chance that ambiguity will arise when trying to apply implicit views to adapt the arguments to the parameter types:...
Read more >
Changelog — Finagle 22.4.0 documentation
finagle-core: Removed the stack param WhenNoNodesOpenParam from LoadBalancerFactory ... Affected clients may now see tracing enabled by default via the Java ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found