Skip to content

private[this] inference does not work for constructor parameters #22620

Open
@yaniskas

Description

@yaniskas

Compiler version

3.6.3

Minimized code

import scala.collection.mutable.ArrayBuffer

class PrivateTest[-M](private val v: ArrayBuffer[M])

Output

-- Error: .\PrivateTest.scala:3:34 ---------------------------------------------
3 |class PrivateTest[-M](private val v: ArrayBuffer[M])
  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |contravariant type M occurs in invariant position in type scala.collection.mutable.ArrayBuffer[M] of value v

Expectation

This code compiles correctly if you use the deprecated private[this] syntax, so according to the Scala 3 reference, it looks like the compiler should treat v as if it had been declared private[this], and the code should compile without errors. It also happens to compile correctly if you do not include the private val declaration at all and let the compiler infer it.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions