Skip to content

Commit

Permalink
Re-use attachment in exportForwarders to handle ambiguous overloads
Browse files Browse the repository at this point in the history
exportForwarders can be called more than once for the same expression
if there are ambiguous overloads.

Just return the already computed ExportForwarders if that happens.

Closes #21071
  • Loading branch information
wjoel committed Sep 3, 2024
1 parent 5e83606 commit 634fcd1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 9 additions & 0 deletions tests/neg/i21071.check
Original file line number Diff line number Diff line change
@@ -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`
21 changes: 21 additions & 0 deletions tests/neg/i21071.scala
Original file line number Diff line number Diff line change
@@ -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
}

???
}
}

0 comments on commit 634fcd1

Please sign in to comment.