Skip to content

Commit 6d4a6c5

Browse files
authored
Merge pull request #119 from scala/backport-lts-3.3-21825
Backport "Nowarn extension matching nonpublic member" to 3.3 LTS
2 parents e0eb805 + e673804 commit 6d4a6c5

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/RefChecks.scala

+13-12
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ object RefChecks {
445445

446446
// todo: align accessibility implication checking with isAccessible in Contexts
447447
def isOverrideAccessOK =
448-
val memberIsPublic = (member.flags & AccessFlags).isEmpty && !member.privateWithin.exists
449448
def protectedOK = !other.is(Protected) || member.is(Protected) // if o is protected, so is m
450449
def accessBoundaryOK =
451450
val ob = other.accessBoundary(member.owner)
@@ -454,7 +453,7 @@ object RefChecks {
454453
def companionBoundaryOK = ob.isClass && !ob.isLocalToBlock && mb.is(Module) && (ob.companionModule eq mb.companionModule)
455454
ob.isContainedIn(mb) || companionBoundaryOK // m relaxes o's access boundary,
456455
def otherIsJavaProtected = other.isAllOf(JavaProtected) // or o is Java defined and protected (see #3946)
457-
memberIsPublic || protectedOK && (accessBoundaryOK || otherIsJavaProtected)
456+
member.isPublic || protectedOK && (accessBoundaryOK || otherIsJavaProtected)
458457
end isOverrideAccessOK
459458

460459
if !member.hasTargetName(other.targetName) then
@@ -1069,16 +1068,18 @@ object RefChecks {
10691068
target.nonPrivateMember(sym.name)
10701069
.filterWithPredicate:
10711070
member =>
1072-
val memberIsImplicit = member.info.hasImplicitParams
1073-
val paramTps =
1074-
if memberIsImplicit then methTp.stripPoly.firstParamTypes
1075-
else methTp.firstExplicitParamTypes
1076-
1077-
paramTps.isEmpty || memberIsImplicit && !methTp.hasImplicitParams || {
1078-
val memberParamTps = member.info.stripPoly.firstParamTypes
1079-
!memberParamTps.isEmpty
1080-
&& memberParamTps.lengthCompare(paramTps) == 0
1081-
&& memberParamTps.lazyZip(paramTps).forall((m, x) => x frozen_<:< m)
1071+
member.symbol.isPublic && {
1072+
val memberIsImplicit = member.info.hasImplicitParams
1073+
val paramTps =
1074+
if memberIsImplicit then methTp.stripPoly.firstParamTypes
1075+
else methTp.firstExplicitParamTypes
1076+
1077+
paramTps.isEmpty || memberIsImplicit && !methTp.hasImplicitParams || {
1078+
val memberParamTps = member.info.stripPoly.firstParamTypes
1079+
!memberParamTps.isEmpty
1080+
&& memberParamTps.lengthCompare(paramTps) == 0
1081+
&& memberParamTps.lazyZip(paramTps).forall((m, x) => x frozen_<:< m)
1082+
}
10821083
}
10831084
.exists
10841085
if !target.typeSymbol.denot.isAliasType && !target.typeSymbol.denot.isOpaqueAlias && hidden

Diff for: tests/warn/i21816.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
case class CC(a: String, b: String) extends Iterable[String] {
3+
override def iterator: Iterator[String] = Iterator(a, b)
4+
}
5+
6+
trait T {
7+
extension (cc: CC) def className: String = "foo"
8+
}
9+
10+
object O extends T {
11+
def foo = {
12+
val cc = CC("a", "b")
13+
println(cc.className)
14+
}
15+
}
16+
17+
@main def main() = O.foo

0 commit comments

Comments
 (0)