scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Package protected class cannot extend a public sealed generic class with a protected constructor #12756

Closed noresttherein closed 1 year ago

noresttherein commented 1 year ago

Reproduction steps

Scala version: 2.13.10

package test {
    sealed class Seal[X] protected (x :String) {
        protected def this() = this("")
    }
    protected[test] class Walrus extends Seal
}

Problem

constructor Seal in class Seal cannot be accessed in package test from package test
 Access to protected constructor Seal not permitted because
 enclosing package test is not a subclass of
 class Seal in package test where target is defined
    protected[test] class Walrus extends Seal

A bummer because it is a useful technique for 'unsealing' a class for a class in another file.

SethTisue commented 1 year ago

assuming you mean extends Seal[String] or some such and not just extends Seal (because otherwise "Missing type parameter for test.Seal"), Scala 3 accepts this

offhand this like something we'd be unlikely to tinker with in a Scala 2 context, but I could certainly be wrong

som-snytt commented 1 year ago

Duplicates https://github.com/scala/bug/issues/12379