Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Add clause for protected visibility from package objects" #18148

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ class CommunityBuildTestC:
@Test def sconfig = projects.sconfig.run()
@Test def shapeless = projects.shapeless.run()
@Test def sourcecode = projects.sourcecode.run()

// Disabled. Currently fails in FutureMatchers.scala. The call to
// `checkResultFailure` goes to a protected method which is not accessible.
// I tried to fix it, but get test failures.
// @Test def specs2 = projects.specs2.run()
@Test def specs2 = projects.specs2.run()

@Test def stdLib213 = projects.stdLib213.run()
@Test def ujson = projects.ujson.run()
Expand Down
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -907,10 +907,13 @@ object SymDenotations {
false
val cls = owner.enclosingSubClass
if !cls.exists then
val encl = if ctx.owner.isConstructor then ctx.owner.enclosingClass.owner.enclosingClass else ctx.owner.enclosingClass
fail(i"""
| Access to protected $this not permitted because enclosing ${encl.showLocated}
| is not a subclass of ${owner.showLocated} where target is defined""")
if pre.termSymbol.isPackageObject && accessWithin(pre.termSymbol.owner) then
true
else
val encl = if ctx.owner.isConstructor then ctx.owner.enclosingClass.owner.enclosingClass else ctx.owner.enclosingClass
fail(i"""
| Access to protected $this not permitted because enclosing ${encl.showLocated}
| is not a subclass of ${owner.showLocated} where target is defined""")
else if isType || pre.derivesFrom(cls) || isConstructor || owner.is(ModuleClass) then
// allow accesses to types from arbitrary subclasses fixes #4737
// don't perform this check for static members
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i18124/definition.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// definition.scala
package oolong.bson:

trait BsonValue
protected def merge(
base: BsonValue,
patch: BsonValue,
arraySubvalues: Boolean = false
): BsonValue = ???

private def foo: Int = 1

package inner:
protected[bson] def bar = 2

8 changes: 8 additions & 0 deletions tests/pos/i18124/usage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// usage.scala
package oolong.bson

extension (bv: BsonValue)
def :+(other: BsonValue): BsonValue = merge(other, bv, false)

val x = foo
val y = inner.bar
Loading