Skip to content

Commit 09f9343

Browse files
committed
Tweak duplicate export detection
1 parent 620e70b commit 09f9343

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
@@ -1098,10 +1098,14 @@ class Namer { typer: Typer =>
10981098
val sym = mbr.symbol
10991099
if !sym.isAccessibleFrom(pathType) then
11001100
No("is not accessible")
1101-
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) then
1101+
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) || sym.isAllOf(JavaModule) then
11021102
Skip
11031103
else if cls.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred)) then
11041104
No(i"is already a member of $cls")
1105+
else if pathMethod.exists && mbr.isType then
1106+
No("is a type, so it cannot be exported as extension method")
1107+
else if pathMethod.exists && sym.is(ExtensionMethod) then
1108+
No("is already an extension method, cannot be exported into another one")
11051109
else if targets.contains(alias) then
11061110
No(i"clashes with another export in the same export clause")
11071111
else if sym.is(Override) then
@@ -1110,12 +1114,6 @@ class Namer { typer: Typer =>
11101114
) match
11111115
case Some(other) => No(i"overrides ${other.showLocated}, which is already a member of $cls")
11121116
case None => Yes
1113-
else if sym.isAllOf(JavaModule) then
1114-
Skip
1115-
else if pathMethod.exists && mbr.isType then
1116-
No("is a type, so it cannot be exported as extension method")
1117-
else if pathMethod.exists && sym.is(ExtensionMethod) then
1118-
No("is already an extension method, cannot be exported into another one")
11191117
else
11201118
Yes
11211119
}
@@ -1243,12 +1241,13 @@ class Namer { typer: Typer =>
12431241
val size = buf.size
12441242
val mbrs = List(name, name.toTypeName).flatMap(pathType.member(_).alternatives)
12451243
mbrs.foreach(addForwarder(alias, _, span))
1246-
targets += alias
12471244
if buf.size == size then
12481245
val reason = mbrs.map(canForward(_, alias)).collect {
12491246
case CanForward.No(whyNot) => i"\n$path.$name cannot be exported because it $whyNot"
12501247
}.headOption.getOrElse("")
12511248
report.error(i"""no eligible member $name at $path$reason""", ctx.source.atSpan(span))
1249+
else
1250+
targets += alias
12521251

12531252
def addWildcardForwardersNamed(name: TermName, span: Span): Unit =
12541253
List(name, name.toTypeName)

0 commit comments

Comments
 (0)