Skip to content

Commit ba88bf6

Browse files
authored
Tweak selection from self types (#18467)
Previously, we rejected the case where a symbol of a self type selection was private if it was not of the enclosing class. But that symbol could shadow a non-private symbol in a base class, so have to treat that case as well. Fixes #18351
2 parents 5318d68 + cbe1fde commit ba88bf6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,14 @@ object Types {
854854
// is made to save execution time in the common case. See i9844.scala for test cases.
855855
def qualifies(sd: SingleDenotation) =
856856
!sd.symbol.is(Private) || sd.symbol.owner == tp.cls
857-
d match
857+
d.match
858858
case d: SingleDenotation => if qualifies(d) then d else NoDenotation
859859
case d => d.filterWithPredicate(qualifies)
860+
.orElse:
861+
// Only inaccessible private symbols were found. But there could still be
862+
// shadowed non-private symbols, so as a fallback search for those.
863+
// Test case is i18361.scala.
864+
findMember(name, pre, required, excluded | Private)
860865
else d
861866
else
862867
// There is a special case to handle:

tests/pos/i18361.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test1:
2+
class Service(val name: String)
3+
class CrudService(name: String) extends Service(name)
4+
5+
trait Foo { self: CrudService =>
6+
val x = self.name
7+
}
8+
9+
package test2:
10+
abstract class Service[F[_]](val name: String)
11+
abstract class CrudService[F[_]](name: String) extends Service[F](name)
12+
13+
trait Foo[F[_]] { self: CrudService[?] =>
14+
val x = self.name
15+
}

0 commit comments

Comments
 (0)