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

The protected keyword makes it impossible for the subclass to use the default value of the superclass constructor #16814

Closed
makingthematrix opened this issue Feb 2, 2023 · 4 comments · Fixed by #16977
Assignees
Milestone

Comments

@makingthematrix
Copy link
Contributor

makingthematrix commented Feb 2, 2023

Compiler version

I was able to narrow down the time when the bug originated to somewhere between 3.3.0-RC1-bin-20221122-794818b-NIGHTLY and 3.3.0-RC1. The bug is still present in 3.3.0-RC2.

Minimized code

  class Foo protected (foo: Int = 0) { }
  class Bar extends Foo

Output

In Scala 3.2.1 the above code compiles.
Bar extends Foo without providing a value for foo, but there is the default value 0 in the superclass constructor so all is good.

In Scala 3.3.0-RC1/RC2 (but not yet in the nightly I specified above) it fails with:

[error]    |  class Bar extends Foo
[error]    |                    ^^^
[error]    |missing argument for parameter foo of constructor Foo in class Foo: (foo: Int): 
[error] one error found

It compiles again either if I remove protected from the superclass constructor, or if I provide the value for foo explicitly:

class Foo(foo: Int = 0) { } // this is ok
class Bar extends Foo 
// ---
class Foo protected (foo: Int = 0) { }
class Bar extends Foo(0) // this is ok

Expectation

The original minimized code should compile.

@makingthematrix makingthematrix added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 2, 2023
@SethTisue
Copy link
Member

I'm curious which PR is responsible.

@soronpo
Copy link
Contributor

soronpo commented Feb 2, 2023

I'm more curious how the community build and CI didn't catch this sort of thing

@mbovel
Copy link
Member

mbovel commented Feb 5, 2023

Bisected to #16538.

@mbovel mbovel added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 5, 2023
@SethTisue
Copy link
Member

fyi @dwijnand

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.

6 participants