Skip to content

Commit

Permalink
Tweak duplicate export detection
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Apr 25, 2022
1 parent 9314388 commit 3c55674
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,14 @@ class Namer { typer: Typer =>
val sym = mbr.symbol
if !sym.isAccessibleFrom(pathType) then
No("is not accessible")
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) then
else if sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge) || sym.is(ConstructorProxy) || sym.isAllOf(JavaModule) then
Skip
else if cls.derivesFrom(sym.owner) && (sym.owner == cls || !sym.is(Deferred)) then
No(i"is already a member of $cls")
else if pathMethod.exists && mbr.isType then
No("is a type, so it cannot be exported as extension method")
else if pathMethod.exists && sym.is(ExtensionMethod) then
No("is already an extension method, cannot be exported into another one")
else if targets.contains(alias) then
No(i"clashes with another export in the same export clause")
else if sym.is(Override) then
Expand All @@ -1111,12 +1115,6 @@ class Namer { typer: Typer =>
) match
case Some(other) => No(i"overrides ${other.showLocated}, which is already a member of $cls")
case None => Yes
else if sym.isAllOf(JavaModule) then
Skip
else if pathMethod.exists && mbr.isType then
No("is a type, so it cannot be exported as extension method")
else if pathMethod.exists && sym.is(ExtensionMethod) then
No("is already an extension method, cannot be exported into another one")
else
Yes
}
Expand Down Expand Up @@ -1245,12 +1243,13 @@ class Namer { typer: Typer =>
val size = buf.size
val mbrs = List(name, name.toTypeName).flatMap(pathType.member(_).alternatives)
mbrs.foreach(addForwarder(alias, _, span))
targets += alias
if buf.size == size then
val reason = mbrs.map(canForward(_, alias)).collect {
case CanForward.No(whyNot) => i"\n$path.$name cannot be exported because it $whyNot"
}.headOption.getOrElse("")
report.error(i"""no eligible member $name at $path$reason""", ctx.source.atSpan(span))
else
targets += alias

def addWildcardForwardersNamed(name: TermName, span: Span): Unit =
List(name, name.toTypeName)
Expand Down

0 comments on commit 3c55674

Please sign in to comment.