Skip to content

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

Closed
@makingthematrix

Description

@makingthematrix

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions