Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow override protected[C] in companion (#14105)
* Allow override protected[C] in companion When extending C in its companion, allow override protected[C] where C denotes the enclosing companion module of C. Lookup of local companion is broken under `-from-tasty`, so this accommodation is disallowed for local companions. * RefChecks: add reference to related issue in comment Co-authored-by: Guillaume Martres <smarter@ubuntu.com> Co-authored-by: Guillaume Raffin <theelectronwill@gmail.com> Co-authored-by: Guillaume Martres <smarter@ubuntu.com>
- Loading branch information
1 parent
29fc554
commit fa08d00
Showing
3 changed files
with
40 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
object X { | ||
// restriction in Scala 2 for local companions | ||
// restriction in Scala 3 under -from-tasty | ||
def m: Int = { | ||
trait C { | ||
protected[C] def f: Int | ||
} | ||
object C { | ||
class C2 extends C { | ||
protected[C] def f: Int = 42 // error // ok except for restrictions noted | ||
def test = f | ||
} | ||
} | ||
C.C2().test | ||
} | ||
} |
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,10 @@ | ||
|
||
trait Base { | ||
protected[Base] def f: Int | ||
} | ||
object Base { | ||
class Child extends Base { | ||
protected[Base] def f: Int = 42 // ok | ||
def test = f | ||
} | ||
} |