Skip to content

Constructor parameters: (a: Int = 0)(b: Int = 0) is not equivalent to ()() #18006

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

Closed
Sporarum opened this issue Jun 19, 2023 · 2 comments
Closed

Comments

@Sporarum
Copy link
Contributor

Compiler version

Scala 3.3.0

Minimized code & Output

trait Obj1(a: Int = 0)(b: Int = 0)

trait Obj2()()

// Expected:
new Obj1()(){}
new Obj2()(){}

// Unexpected:
new Obj1{}      // missing arguments for constructor Obj1 in trait Obj1
new Obj2{}

https://scastie.scala-lang.org/SRf7kAOKQWuUAm8yegbFtg

Expectation

No error, or a similar error for Obj2{} (or better)

@Sporarum Sporarum added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 19, 2023
@Sporarum
Copy link
Contributor Author

Sporarum commented Jun 19, 2023

Has impact on trait parameters: #17988

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

odersky commented Jun 24, 2023

It's because of this test in Typer.ensureConstrCall:

psym.primaryConstructor.info.takesParams

The test does not take default parameters into account (it cannot, for reasons given below). For Obj1 it returns false, for Obj2, true. That is the fork in the treatment. If the primaryConstructor takes parameters, we need to consstruct a constructor application to pass default arguments. But we can insert at most one (), which can then expand to default parameters, hence the error.

I don't think it's worth trying to fix this.

@odersky odersky closed this as completed Jun 24, 2023
@bishabosha bishabosha closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants