Skip to content

Case class with protected constructor has a public apply #14187

Closed
@dwijnand

Description

@dwijnand

Compiler version

3.1.0

Minimized code

sealed case class Foo protected (i: Int, j: Int)

final class Bar(n: Int) extends Foo(n, n)

class Other:
  def foo  = Foo(1, 2)
  def foo2 = Foo.apply(1, 2)

Output

$ scalac -3.1.0 foo.scala
$

Expectation

I shouldn't be able to construct a case class with a protected constructor in an Other class.

Notes

Looks like this was changed in #5830. I'd argue a protected constructor should mean everything a private one means with the addition that it can have subclasses because they can access the constructor. Meaning it shouldn't have an apply method (because it makes no sense in an object and may even will impact overload resolution) and therefore it shouldn't mixin its FunctionX either.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions