Skip to content

Commit 3c55674

Browse files
committed
Tweak duplicate export detection
1 parent 9314388 commit 3c55674

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,10 +1099,14 @@ class Namer { typer: Typer =>
10991099
val sym = mbr.symbol
11001100
if !sym.isAccessibleFrom(pathType) then
11011101
No("is not accessible")
1102-
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) then
1102+
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) || sym.isAllOf(JavaModule) then
11031103
Skip
11041104
else if cls.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred)) then
11051105
No(i"is already a member of $cls")
1106+
else if pathMethod.exists && mbr.isType then
1107+
No("is a type, so it cannot be exported as extension method")
1108+
else if pathMethod.exists && sym.is(ExtensionMethod) then
1109+
No("is already an extension method, cannot be exported into another one")
11061110
else if targets.contains(alias) then
11071111
No(i"clashes with another export in the same export clause")
11081112
else if sym.is(Override) then
@@ -1111,12 +1115,6 @@ class Namer { typer: Typer =>
11111115
) match
11121116
case Some(other) => No(i"overrides ${other.showLocated}, which is already a member of $cls")
11131117
case None => Yes
1114-
else if sym.isAllOf(JavaModule) then
1115-
Skip
1116-
else if pathMethod.exists && mbr.isType then
1117-
No("is a type, so it cannot be exported as extension method")
1118-
else if pathMethod.exists && sym.is(ExtensionMethod) then
1119-
No("is already an extension method, cannot be exported into another one")
11201118
else
11211119
Yes
11221120
}
@@ -1245,12 +1243,13 @@ class Namer { typer: Typer =>
12451243
val size = buf.size
12461244
val mbrs = List(name, name.toTypeName).flatMap(pathType.member(_).alternatives)
12471245
mbrs.foreach(addForwarder(alias, _, span))
1248-
targets += alias
12491246
if buf.size == size then
12501247
val reason = mbrs.map(canForward(_, alias)).collect {
12511248
case CanForward.No(whyNot) => i"\n$path.$name cannot be exported because it $whyNot"
12521249
}.headOption.getOrElse("")
12531250
report.error(i"""no eligible member $name at $path$reason""", ctx.source.atSpan(span))
1251+
else
1252+
targets += alias
12541253

12551254
def addWildcardForwardersNamed(name: TermName, span: Span): Unit =
12561255
List(name, name.toTypeName)

0 commit comments

Comments
 (0)