-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Wrong compiler error message while using contextual functions #12941
Comments
Here the repo: https://github.com/BarkingBad/dotty-bug-12941/blob/master/src/main/scala/Main.scala Apparently making A abstract and |
Further minimized without the junit dependency: class I:
def runSth: Int = 1
abstract class A:
def myFun(op: I ?=> Unit) =
op(using I())
1
class B extends A
def assertEquals(x: String, y: Int, z: Int): Unit = ()
@main def hello: Unit =
B().myFun {
val res = summon[I].runSth
assertEquals("", 1, res, "asd")
println("Hello!")
} |
Test output:
The first error is unexpected. |
Beat our heads on this for a while at the spree, with Jiri and Gagandeep. What happens here is that when the second error is encountered, the compiler attempts error recovery, and when it does that,
the We aren't even sure what the right solution plan is here. Some approaches we considered:
|
I could be interested in pursuing this further, but I feel like we need expert advice on what the appropriate solution plan is. If we had a solution plan sort of sketched out for us, maybe we could try to implement it. |
Jiri, Gagandeep, could you leave your even-more-minimized version of the code here? |
Minimized code- object A:
def myFun(op: String ?=> Unit) = ()
@main def func: Unit =
A.myFun {
val res = summon[String]
println(ress)
} |
Did you find out where that recovery is triggered? |
The error recovery is triggered in |
I have investigated the minimized code that Gagandeep proposed above a little further. The compiler behaves slightly differently on this code than the original code, but I believe that the difference does not matter here. The original code was calling a function with valid arguments, but the wrong number of them. The minimized code is calling a function with the correct number of arguments, but the argument itself is invalid. In this new code, the problematic recovery attempt does happen on the wrong line first, does not succeed and then it happens again on the entire function literal and produces the same unexpected diagnostic as the original code. As I mentioned above, the error recovery happens in The first call to
and this call eventually leads to a recursive call to
The outer call to The logic of this error recovery attempt is implemented in
The line Source references based on commit |
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Was exp:intermediate a joke? |
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Don't retypecheck erroneous arguments when trying conversions or extensions on the function part. Generally, we should avoid typechecking untyped trees several times, this can quickly explode exponentially. Fixes scala#12941
Compiler version
Example is at 3.0.0 but the problem still exists for the newest master (commit
b3ade17
)Minimized code
Output
Expectation
Error should point to wrong
assertEquals
dispatch instead ofno implicit argument of type I
.However, if we change commented line, Program succeedes
I think it only exists for calling
Java
functions, however for scala function it returns BOTHno implicit
andNone of the overloaded alternatives of method assertEquals in object Assert with types
errors which is somehow more correct. I'll link clean repo with reproduction.The text was updated successfully, but these errors were encountered: