diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 44844195258a..3e4d740c87ac 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1411,10 +1411,11 @@ class Namer { typer: Typer => forwarders.derivedCons(forwarder2, avoidClashes(forwarders2)) case Nil => forwarders - addForwarders(selectors, Nil) - val forwarders = avoidClashes(buf.toList) - exp.pushAttachment(ExportForwarders, forwarders) - forwarders + exp.getAttachment(ExportForwarders).getOrElse: + addForwarders(selectors, Nil) + val forwarders = avoidClashes(buf.toList) + exp.pushAttachment(ExportForwarders, forwarders) + forwarders end exportForwarders /** Add forwarders as required by the export statements in this class */ diff --git a/tests/neg/i21071.check b/tests/neg/i21071.check new file mode 100644 index 000000000000..b2a3233a31c0 --- /dev/null +++ b/tests/neg/i21071.check @@ -0,0 +1,9 @@ +-- [E051] Reference Error: tests/neg/i21071.scala:9:2 ------------------------------------------------------------------ +9 | foo { // error + | ^^^ + | Ambiguous overload. The overloaded alternatives of method foo in object MySuite with types + | (a: String): Nothing + | (a: List[String]): Nothing + | both match arguments ((??? : => Nothing)) + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i21071.scala b/tests/neg/i21071.scala new file mode 100644 index 000000000000..ac222cad7936 --- /dev/null +++ b/tests/neg/i21071.scala @@ -0,0 +1,21 @@ +trait Service { + def method: String +} + +object MySuite { + def foo(a: List[String]) = ??? + def foo(a: String) = ??? + + foo { // error + + new Service { + private val underlying: Service = ??? + private val s = "foo" + + export underlying.* + export s.toLowerCase + } + + ??? + } +}