-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Decouple ImplicitFunctionN from FunctionN. #2008
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
Decouple ImplicitFunctionN from FunctionN. #2008
Conversation
ca2d865
to
41b1b97
Compare
This removes an illegal method override mentioned in scala#2000.
41b1b97
to
ebf7fd4
Compare
case Closure(Nil, id @ Ident(nme.ANON_FUN), _) => | ||
val adaptToPrototype = | ||
if (defn.isFunctionType(pt)) { | ||
// convert implicit function to function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the change in this logic. Questions:
- Do we want to convert implicit functions to functions, or to other SAM types? Does this case even arise? I was assuming that an implicit function is always immediately applied.
- What would happen if we kept the previous code here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is from implicit function to function, previously this worked because implicit functions where a subtype of functions.
A concrete case that fails without this change is
-- [E007] Type Mismatch Error: /Users/nicolasstucki/GitHub/dotty/tests/partest-generated/run/implicitFuns.scala --------
148 | println(if (thisTransaction.isAborted) "aborted" else s"result: $res")
| ^
| found: implicit Transaction => Unit
| required: Transaction => Any
where
def transaction[T](op: Transaction => T) = {
...
}
def main(args: Array[String]) = {
transaction {
implicit thisTransaction =>
val res = f1(args.length)
println(if (thisTransaction.isAborted) "aborted" else s"result: $res")
}
}
Is there a better way to implement this coercion from implicit function to function?
@nicolasstucki Thanks for explaining! So we need to make implicit functions compatible with normal functions after all. This means we have the following choices:
To come to a resolution here I think it's best to answer first the question whether implicit functions should be final or not. Making them non-final gives us a lot of new power. For instance:
Super powerful. But do we want it? |
I do not have any use cases for this. We should still double check that with #2014 we can not override the apply of an implicit function with |
I tried it in the REPL: Now it's no longer possible. |
Then this PR is irrelevant now. |
This removes an illegal method override mentioned in #2000.