Code not compiling when Unit-returning SAM and overloaded methods involved

It is often the case that overloading a method cripples type inference, though there have been made some improvements in that area. So that to me is not a good argument to make certain code not compile. However there may be other arguments in favor of limiting automatic ()-insertion more than it currently is.

For instance

import some.fp.api.Task

val task: Task[Unit] = 
  Task {
    println("starting inner task")
    Task(println("running inner task"))
  } 
  // oops forgot to flatten, but compiles anyway

task.run()
// out: starting inner task
1 Like