Skip to content

Commit

Permalink
Backport "Re-use attachment in exportForwarders to handle ambiguous o…
Browse files Browse the repository at this point in the history
…verloads" to LTS (#22116)

Backports #21518 to the 3.3.5.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Dec 4, 2024
2 parents 2a55db1 + 7215aa6 commit ee59f07
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 @@ -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 */
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 ee59f07

Please sign in to comment.