Skip to content

Commit 8f18883

Browse files
committed
Export: Refine canForward for selections on this
1 parent 590691b commit 8f18883

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,12 @@ class Namer { typer: Typer =>
11791179
No("is not accessible")
11801180
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) || sym.isAllOf(JavaModule) then
11811181
Skip
1182-
else if cls.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred)) then
1182+
// if the cls is a subclass of the owner of the symbol
1183+
// and either
1184+
// * the symbols owner is the cls itself
1185+
// * 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
11831188
No(i"is already a member of $cls")
11841189
else if pathMethod.exists && mbr.isType then
11851190
No("is a type, so it cannot be exported as extension method")

tests/neg/exports3.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait P:
2+
def foo: Int
3+
4+
class A extends P:
5+
export this.foo // error

0 commit comments

Comments
 (0)