Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Type inference for lambda parameters should be able to take the body of the lambda into account #17771

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

Closed
civp opened this issue Mar 8, 2022 · 1 comment
Labels
stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@civp
Copy link

civp commented Mar 8, 2022

Compiler version

3.1.1

Minimized code

class A
class B extends A

class C(b: B)
class D(b: B)(x: Int)

def c(b: B): B = b
def d(b: B)(x: Int): B = b

def f[S <: A, T](g: S => T): S => T = g

object Main {
  def main(args: Array[String]): Unit =
    // f(x => C(x)) // compiles
    f(x => D(x)(0)) // doesn't compile
    // f(x => c(x)) // compiles
    f(x => d(x)(0)) // doesn't compile
}

Output

-- [E007] Type Mismatch Error: Test.scala:15:13 --------------------------------
15 |    f(x => D(x)(0)) // doesn't compile
   |             ^
   |             Found:    (x : A)
   |             Required: B

longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: Test.scala:17:13 --------------------------------
17 |    f(x => d(x)(0)) // doesn't compile
   |             ^
   |             Found:    (x : A)
   |             Required: B

longer explanation available when compiling with `-explain`
2 errors found

Expectation

The result of type inference should be (x: B) becaue B is a subclass of A.

The program should compile.

@civp civp added the stat:needs triage Every issue needs to have an "area" and "itype" label label Mar 8, 2022
@smarter
Copy link
Member

smarter commented Mar 8, 2022

This is the sort of things that #9076 aimed to fix but it's far from trivial. As things stand this is an accepted limitation of type inference so I'll move this to the feature requests repo.

@smarter smarter transferred this issue from scala/scala3 Mar 8, 2022
@smarter smarter changed the title A type inference bug with anonymous functions and currying Type inference for lambda parameters should be able to take the body of the lambda into account Mar 8, 2022
@ckipp01 ckipp01 transferred this issue from lampepfl/dotty-feature-requests Jun 5, 2023
@scala scala locked and limited conversation to collaborators Jun 5, 2023
@ckipp01 ckipp01 converted this issue into discussion #17772 Jun 5, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

2 participants