Skip to content

Intersection of implicit function types is not an implicit function type #5473

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
smarter opened this issue Nov 19, 2018 · 3 comments
Closed

Comments

@smarter
Copy link
Member

smarter commented Nov 19, 2018

E.g.:

trait A
trait B

object Test {
  val x: (implicit A => Int) & (implicit B => Int) = 42
    // error: found: 42, required: (implicit A => Int) & (implicit B => Int)
}

We probably should treat this as an implicit function type, otherwise distributing an intersection (something that the compiler will do in some situations) would change the semantics. But then should we allow this too ?

trait A
trait Foo extends ImplicitFunction[A, Int]

object Test {
  val x: Foo = 42
}

@odersky WDYT ?

@odersky
Copy link
Contributor

odersky commented Nov 20, 2018

Maybe ImplicitFunction should be final?

@smarter
Copy link
Member Author

smarter commented Nov 20, 2018

It can't be final since implicit function literals are desugared to anonymous subclasses of ImplicitFunctionN, at best we could disallow non-anonymous subclasses of it ?

@odersky
Copy link
Contributor

odersky commented Mar 6, 2020

I think the answer is: intersections are not function types whether implicit or not. So far I have not seen that distributing an intersection will cause problems. Let's re-open if there is a case. In that case we shyould probably restrict the distribution itself to avoid a change in semantics.

@odersky odersky closed this as completed Mar 6, 2020
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