Scala 3 contextual abstractions conflict with overloading

79 Views Asked by At

Contextual abstractions seem to interfere with overloading, and produce unexpected compilation error messages. This here works:

def foo(b: Double ?=> Unit): Double ?=> Unit = ()
// def foo(a: String): Unit = () // uncommenting causes compilation error

@main def demo(): Unit =
  given c: Double = 299792458.0
  foo {
    println("ok")
  } 

But as soon as we uncomment the overloaded def foo, it no longer compiles with the error message

None of the overloaded alternatives of method foo in package p with types

(a: String): Unit

(b: (Double) ?=> Unit): (Double) ?=> Unit

match arguments (Unit)

(It's same on 3.1.0 and 3.0.x)

Any ideas what exactly happens here? Is there any reason why this would be the expected behavior? Any proposals on how to make it compile with two overloaded foo definitions?

0

There are 0 best solutions below