Skip to content

Commit 04ad901

Browse files
committed
Tweak duplicate export detection
1 parent 0f9a163 commit 04ad901

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
}
@@ -1244,12 +1242,13 @@ class Namer { typer: Typer =>
12441242
val size = buf.size
12451243
val mbrs = List(name, name.toTypeName).flatMap(pathType.member(_).alternatives)
12461244
mbrs.foreach(addForwarder(alias, _, span))
1247-
targets += alias
12481245
if buf.size == size then
12491246
val reason = mbrs.map(canForward(_, alias)).collect {
12501247
case CanForward.No(whyNot) => i"\n$path.$name cannot be exported because it $whyNot"
12511248
}.headOption.getOrElse("")
12521249
report.error(i"""no eligible member $name at $path$reason""", ctx.source.atSpan(span))
1250+
else
1251+
targets += alias
12531252

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

0 commit comments

Comments
 (0)