Skip to content

Commit 29c9945

Browse files
committed
Exports: Improve detection of selections on this
Fixes the typeclass-aggregates test. We now reject selections on `this` in `canForward` only if the selection has an empty qualifier.
1 parent 8f18883 commit 29c9945

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,13 @@ class Namer { typer: Typer =>
11751175
def canForward(mbr: SingleDenotation, alias: TermName): CanForward = {
11761176
import CanForward.*
11771177
val sym = mbr.symbol
1178+
/**
1179+
* Check the export selects an abstract member (issue #22147).
1180+
*/
1181+
def isAbstractMember: Boolean = sym.is(Deferred) && (expr match
1182+
case ths: This if ths.qual.isEmpty => true
1183+
case _ => false
1184+
)
11781185
if !sym.isAccessibleFrom(pathType) then
11791186
No("is not accessible")
11801187
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) || sym.isAllOf(JavaModule) then
@@ -1183,8 +1190,8 @@ class Namer { typer: Typer =>
11831190
// and either
11841191
// * the symbols owner is the cls itself
11851192
// * the symbol is not a deferred symbol
1186-
// * the symbol is a deferred symbol and the selection is on a This
1187-
else if cls.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred) || (sym.is(Deferred) && expr.isInstanceOf[This])) then
1193+
// * the symbol is an abstract member #22147
1194+
else if cls.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred) || isAbstractMember) then
11881195
No(i"is already a member of $cls")
11891196
else if pathMethod.exists && mbr.isType then
11901197
No("is a type, so it cannot be exported as extension method")

0 commit comments

Comments
 (0)