Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use attachment in exportForwarders to handle ambiguous overloads #21518

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}

???
}
}
Loading