Skip to content
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

Type inference issues when using intersection types #18226

Closed
IndiscriminateCoding opened this issue Jul 17, 2023 · 3 comments · Fixed by #18235
Closed

Type inference issues when using intersection types #18226

IndiscriminateCoding opened this issue Jul 17, 2023 · 3 comments · Fixed by #18235

Comments

@IndiscriminateCoding
Copy link

Compiler version

3.3.0

Minimized code

trait F[-R]

trait Row[A]

def eliminateInt[R](f: F[R & Row[Int]]): F[R] = new F[R] {}

val x = new F[Row[Int] & Row[String]] {}

val _ = eliminateInt[Row[String]](x) // compiles OK when given explicit type
val _ = eliminateInt(x) // error!

Output

Found:    (app.x : app.F[app.Row[Int] & app.Row[String]])
Required: app.F[app.Row[Int]]

Expectation

I expect compiler to be able to infer [R] instantiation based on a type of a passed value.

@IndiscriminateCoding IndiscriminateCoding added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 17, 2023
@nicolasstucki nicolasstucki added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 17, 2023
@nicolasstucki
Copy link
Contributor

I'm not sure if eliminateInt makes sense. Consider eliminateInt[Row[Int] & Row[String]](x) which is a correct type for eliminateInt but does not eliminate the Int.

odersky added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
Fixes scala#18226

Might fix some other reported issues with AndTypes as well.
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
Fixes scala#18226

Might fix some other reported issues with AndTypes as well.
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
Fixes scala#18226

Might fix some other reported issues with AndTypes as well.
@odersky odersky removed their assignment Jul 18, 2023
@odersky
Copy link
Contributor

odersky commented Jul 18, 2023

I tried but #18235 got stuck with a zio problem, which someone else will need to debug.

@odersky odersky self-assigned this Jul 18, 2023
@odersky
Copy link
Contributor

odersky commented Jul 18, 2023

@smarter unstuck #18235 with a minimization. So fixing efforts continue...

odersky added a commit that referenced this issue Jul 19, 2023
Fixes #18226
Fixes #12077 

Might fix some other reported issues with AndTypes as well.
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants