-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14266 from dwijnand/protected-apply
- Loading branch information
Showing
4 changed files
with
30 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
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) // error | ||
def foo2 = Foo.apply(1, 2) // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,45 @@ | ||
case class A private (i: Int) | ||
object A { | ||
def a0 = new A(0) // constructor is accessible in companion | ||
def a = A(1).copy(2) // apply and copy are accessible in companion | ||
} | ||
|
||
case class B private (i: Int) { // no user-defined companion object, should compile | ||
def b0 = new B(0) // constructor is accessible | ||
def b = B(1).copy(2) // apply and copy are accessible | ||
} | ||
|
||
object qualified_private { | ||
case class A private[qualified_private] (i: Int) | ||
object A { | ||
def a0 = new A(0) // constructor is accessible in companion | ||
def a = A(1).copy(2) // apply and copy are accessible in companion | ||
} | ||
|
||
def a0 = new A(0) // constructor is accessible in qualified_private object | ||
def a = A(1).copy(2) // apply and copy are accessible in qualified_private object | ||
|
||
case class B private[qualified_private] (i: Int) { // no user-defined companion object, should compile | ||
def b0 = new B(0) // constructor is accessible | ||
def b = B(1).copy(2) // apply and copy are accessible | ||
} | ||
|
||
def b0 = new B(0) // constructor is accessible in qualified_private object | ||
def b = B(1).copy(2) // apply and copy are accessible in qualified_private object | ||
} | ||
|
||
case class C protected (i: Int) | ||
class CSub extends C(1) { | ||
def c = copy(2) // copy is accessible in subclass | ||
} | ||
object CTest { | ||
def c = C(1) // apply is public | ||
} | ||
|
||
object qualified_protected { | ||
case class C protected[qualified_protected] (i: Int) | ||
class CSub extends C(1) { | ||
def c = copy(2) // copy is accessible in subclass | ||
} | ||
object CTest { | ||
def c = C(1) // apply is public | ||
def checkExtendsFunction: Int => C = C // companion extends (Int => C) | ||
} | ||
def eta: Int => C = C // can eta-expand C.apply method | ||
|
||
def c = C(1).copy(2) | ||
} | ||
object CQualifiedTest { | ||
def c = qualified_protected.C(1) // apply is public | ||
def c0 = new C(0) // constructor is accessible in qualified_protected object | ||
def c = C(1).copy(2) // apply and copy are accessible in qualified_protected object | ||
} |