Skip to content

Result of a method call is not accepted when by-name Unit value is expected once default values are used #15898

Closed
@OndrejSpanel

Description

@OndrejSpanel

Compiler version

3.2.0-RC1

Minimized code

object O {
  class AC(code: => Unit) {
    def apply() = code

    def this(code: => Unit, key: Int, modifiers: Int = 0) = {
      this(code)
    }
  }

  class Doc {
    def method: Boolean = true
  }

  val doc = new Doc

  val ac = new AC(doc.method)
}

Output

None of the overloaded alternatives of constructor AC in class AC with types
 (code: => Unit, key: Int, modifiers: Int): Playground.O.AC
 (code: => Unit): Playground.O.AC
match arguments ((Playground.O.doc.method : => Boolean))

See also https://scastie.scala-lang.org/1LhQNKxeQi2WPLlt8o2Cng

Expectation

The code should compile. It compiles when I remove the secondary constructor or when I remove the default value for parameter modifiers.

Note: the same code compiles fine with Scala 2.12 and 2.13

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions