diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 0a1a70b98bbb..6167db62fbe0 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1452,10 +1452,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 + } + + ??? + } +}