Skip to content

Type inference of lambdas not working #11954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
japgolly opened this issue Mar 30, 2021 · 1 comment
Open

Type inference of lambdas not working #11954

japgolly opened this issue Mar 30, 2021 · 1 comment
Labels
area:typer backlog No work planned on this by the core team for the time being. itype:bug

Comments

@japgolly
Copy link
Contributor

Note: Sorry for the poor title choice. I can't think of a concise way to describe this more accurately. Feel free to rename of course.

Compiler version

3.0.0-RC1

Minimized code

object X {

  class Component[P, S]
  trait Unmounted[P, M]
  trait Mounted[P, S]

  def unmounted[P, S, M](p: P, m: Component[P, S] => M): Unmounted[P, M] =
    ???

  def mounted[P, S](r: Component[P, S]): Mounted[P, S] =
    ???

  def test_KO[P, S](p: P): Unmounted[P, Mounted[P, S]] =
    unmounted(p, mounted) // error

  def test_OK[P, S](p: P): Unmounted[P, Mounted[P, S]] =
    unmounted(p, mounted[P, S]) // ok
}

Output

14 |    unmounted(p, mounted) // error
   |                 ^^^^^^^
   |                 Found:    X.Mounted[P, Any]
   |                 Required: X.Mounted[P, S]

Expectation

It should compile. Scala 2.x compiles without problem.

@smarter
Copy link
Member

smarter commented Mar 30, 2021

It's the usual limitations with type inference going through the body of a lambda, Scala 2 manages to get that example working but it fails if we just replace mounted by x => mounted(x), so it must be a pretty narrow special-case. I'm interested in solving the general problem (#9076), but less so in adding more special-cases, unless they're really common.

@nicolasstucki nicolasstucki changed the title Type inference not working Type inference of lambdas not working Mar 31, 2021
@odersky odersky added the backlog No work planned on this by the core team for the time being. label Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer backlog No work planned on this by the core team for the time being. itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants