Skip to content

Implicit search does not work for union types #11981

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
scf37 opened this issue Apr 3, 2021 · 2 comments
Closed

Implicit search does not work for union types #11981

scf37 opened this issue Apr 3, 2021 · 2 comments

Comments

@scf37
Copy link

scf37 commented Apr 3, 2021

Compiler version

3.0.0-RC1

Minimized code & Output

https://scastie.scala-lang.org/uvY5sVNcSJuNGBiMPM5zKQ

Expectation

Successful compilation but got an error

@odersky
Copy link
Contributor

odersky commented Apr 4, 2021

It does work if you make Null a separate class, or you compile with -Yexplicit-nulls.

The way things are Null is a bottom type. So every class instance of Optional[C] is in fact C.

I tried to change the definition of Optional to

type Optional[A] = A

then the implicit is not found either. So the problem looks like not a problem with union types at all. If Optional[A] defines a real union it works. It looks rather like a limitation of HK type inference that it cannot infer identities. That's actually expected, I think.

@odersky
Copy link
Contributor

odersky commented Apr 6, 2021

I am closing this. Reopen if someone has an argument that identities should be inferrable for HK types and how to do it.

@odersky odersky closed this as completed Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants