-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Chained call to apply after parens forgets to expand first apply #9348
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
Comments
You can minimize this a little further, and there are slightly better workarounds (either using explicit scala> def foo(f: () => () => Int): Int = f()()
def foo(f: () => () => Int): Int
scala> def foo(f: () => () => Int): Int = f.apply.apply
def foo(f: () => () => Int): Int
scala> def foo(f: () => () => Int): Int = f().apply
1 |def foo(f: () => () => Int): Int = f().apply
| ^
| value f does not take parameters I was looking at some of the code related to nullary methods in Dotty recently, and I think the issue is just the |
Ran into the same thing (Dotty 0.27.0-RC1): trait Ref[A] {
def apply(): A
}
trait Test {
val queue: Ref[Vector[Int]]
def test(idx: Int): Int =
queue().apply(idx) // !
}
You have to spell out the first |
I think should close this. Scala 3 will only insert one apply method per call, and I believe that's in balance a positive thing. |
Wait… but this still doesn't work (-M3):
https://scastie.scala-lang.org/ARjsImPPTd68BjRglYancg Here, Scala does insert exactly one Also, you will want to allow multiple insertions for multi-dimensional array look-up, like |
I believe it won't insert an |
Is this just an arbitrary breakage wrt scala 2 or is there a clear motivation why this is simpler? Is the idea to it a tax on nesting use of apply since that is considered bad? |
Nested use of applys can easily become infinite. There needs to be a simple rule to avoid that. |
But there is no nesting in these examples? What would be a problematic case in your opinion? |
The problem is finding a simple rule that will not let the compiler blow up in some (maybe far fetched) cases. The fact that some other cases are safe can make a difference only if there is a simple rule to separate safe from unsafe. |
This was just a bug report about code scala 2 accepted. Travis suggested an edit which caused no tests to fail and fix the issue. I'm confused why this is even in the running for changes in scala for 3. Can you link to bug reports you have had with the scala 2 behavior? I'm sorry if this sounds confrontational buts it's just frustrating that it seems like an arbitrary breakage relative to scala 2 is being thrown in on the hypothesis that it could cause problems despite scala 2 supporting this with no problems that I'm aware of. Scala 2 has gotchas but honestly, in 10 years of use I don't recall this once. |
Minimized code
In this PR: typelevel/cats#3515
part of the diff worked in scala 2, but not 3.
The error message on 0.24.0:
changing the code to:
fixed the matter, but the original code was accepted by scala 2. There may be some language change in scala 3 that made this code illegal, but if that's the case I think a clearer error message would help greatly.
The text was updated successfully, but these errors were encountered: