Skip to content
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

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

Closed
OndrejSpanel opened this issue Aug 24, 2022 · 3 comments · Fixed by #15962

Comments

@OndrejSpanel
Copy link
Member

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

@OndrejSpanel OndrejSpanel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 24, 2022
@som-snytt
Copy link
Contributor

Same result if the ctors are switched (in case it was due to nesting level).

Works with val ac = new AC({doc.method; ()}), so it's an adaptation problem, not just an overloading problem.

@OndrejSpanel
Copy link
Member Author

Note: replacing a default parameter value with an overload also compiles fine:

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

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

  class Doc {
    def method: Boolean = true
  }

  val doc = new Doc

  val ac = new AC(doc.method)
}

@Kordyjan Kordyjan added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 24, 2022
@Kordyjan
Copy link
Contributor

The bug is still present on the current nightly (3.2.1-RC1-bin-20220823-3ad97df-NIGHTLY).

odersky added a commit to dotty-staging/dotty that referenced this issue Sep 4, 2022
When doing a "size-fits" check, we previously only worked with the fact
whether the given alternative had default parameters or not. We know count
the number of default parameters in the applied parameter section, which
gives us a better estimate.

Fixes scala#15898
odersky added a commit to dotty-staging/dotty that referenced this issue Sep 4, 2022
When doing a "size-fits" check, we previously only worked with the fact
whether the given alternative had default parameters or not. We know count
the number of default parameters in the applied parameter section, which
gives us a better estimate.

Fixes scala#15898
KacperFKorban added a commit that referenced this issue Sep 4, 2022
)

When doing a "size-fits" check, we previously only worked with the fact
whether the given alternative had default parameters or not. We know count
the number of default parameters in the applied parameter section, which
gives us a better estimate.

Fixes #15898
mpollmeier pushed a commit to mpollmeier/dotty that referenced this issue Oct 16, 2022
When doing a "size-fits" check, we previously only worked with the fact
whether the given alternative had default parameters or not. We know count
the number of default parameters in the applied parameter section, which
gives us a better estimate.

Fixes scala#15898
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants