@@ -409,19 +409,21 @@ object RefChecks {
409
409
overrideError(" has weaker access privileges; it should not be private" )
410
410
411
411
// todo: align accessibility implication checking with isAccessible in Contexts
412
- val ob = other.accessBoundary(member.owner)
413
- val mb = member.accessBoundary(member.owner)
414
412
def isOverrideAccessOK =
415
- (member.flags & AccessFlags ).isEmpty
416
- && ! member.privateWithin.exists // member is public, or
417
- || (! other.is(Protected ) || member.is(Protected ))
418
- // if o is protected, so is m, and
419
- && (ob.isContainedIn(mb) || other.isAllOf(JavaProtected ))
420
- // m relaxes o's access boundary,
421
- // or o is Java defined and protected (see #3946)
413
+ val memberIsPublic = (member.flags & AccessFlags ).isEmpty && ! member.privateWithin.exists
414
+ def protectedOK = ! other.is(Protected ) || member.is(Protected ) // if o is protected, so is m
415
+ def accessBoundaryOK =
416
+ val ob = other.accessBoundary(member.owner)
417
+ val mb = member.accessBoundary(member.owner)
418
+ // restriction isLocalToBlock because companionModule fails under -from-tasty
419
+ def companionBoundaryOK = ob.isClass && ! ob.isLocalToBlock && mb.is(Module ) && (ob.companionModule eq mb.companionModule)
420
+ ob.isContainedIn(mb) || companionBoundaryOK // m relaxes o's access boundary,
421
+ def otherIsJavaProtected = other.isAllOf(JavaProtected ) // or o is Java defined and protected (see #3946)
422
+ memberIsPublic || protectedOK && (accessBoundaryOK || otherIsJavaProtected)
423
+ end isOverrideAccessOK
422
424
if ! member.hasTargetName(other.targetName) then
423
425
overrideTargetNameError()
424
- else if ( ! isOverrideAccessOK)
426
+ else if ! isOverrideAccessOK then
425
427
overrideAccessError()
426
428
else if (other.isClass)
427
429
// direct overrides were already checked on completion (see Checking.chckWellFormed)
@@ -502,6 +504,7 @@ object RefChecks {
502
504
else
503
505
checkOverrideDeprecated()
504
506
}
507
+ end checkOverride
505
508
506
509
/* TODO enable; right now the annotation is scala-private, so cannot be seen
507
510
* here.
0 commit comments