Skip to content

Wrong compiler error message while using contextual functions #12941

Closed
@BarkingBad

Description

@BarkingBad

Compiler version

Example is at 3.0.0 but the problem still exists for the newest master (commit b3ade17)

Minimized code

class I:
  def runSth: Int = 1

abstract class A:
  def myFun(op: I ?=> Unit) =
    op(using I())
    1

class B extends A
  
@main def hello: Unit = 
  
  B().myFun {
    val res = summon[I].runSth
    org.junit.Assert.assertEquals("", 1, res, "asd")
    // org.junit.Assert.assertEquals("", 1, res)
    println("Hello!")
  }

Output

[error] -- Error: /home/aratajczak/Dokumenty/Praca/Scala/compiler-bug/src/main/scala/Main.scala:14:23 
[error] 14 |    val res = summon[I].runSth
[error]    |                       ^
[error]    |no implicit argument of type I was found for parameter x of method summon in object Predef
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 0 s, completed 25 cze 2021, 16:08:49

Expectation

Error should point to wrong assertEquals dispatch instead of no implicit argument of type I.
However, if we change commented line, Program succeedes

[info] running hello 
Hello!
[success] Total time: 0 s, completed 25 cze 2021, 16:09:29

I think it only exists for calling Java functions, however for scala function it returns BOTH no implicit and None 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions