Skip to content

Commit 7215aa6

Browse files
wjoelWojciechMazur
authored andcommitted
Re-use attachment in exportForwarders to handle ambiguous overloads
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 [Cherry-picked 634fcd1]
1 parent 987e381 commit 7215aa6

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Namer.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -1411,10 +1411,11 @@ class Namer { typer: Typer =>
14111411
forwarders.derivedCons(forwarder2, avoidClashes(forwarders2))
14121412
case Nil => forwarders
14131413

1414-
addForwarders(selectors, Nil)
1415-
val forwarders = avoidClashes(buf.toList)
1416-
exp.pushAttachment(ExportForwarders, forwarders)
1417-
forwarders
1414+
exp.getAttachment(ExportForwarders).getOrElse:
1415+
addForwarders(selectors, Nil)
1416+
val forwarders = avoidClashes(buf.toList)
1417+
exp.pushAttachment(ExportForwarders, forwarders)
1418+
forwarders
14181419
end exportForwarders
14191420

14201421
/** Add forwarders as required by the export statements in this class */

Diff for: tests/neg/i21071.check

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- [E051] Reference Error: tests/neg/i21071.scala:9:2 ------------------------------------------------------------------
2+
9 | foo { // error
3+
| ^^^
4+
| Ambiguous overload. The overloaded alternatives of method foo in object MySuite with types
5+
| (a: String): Nothing
6+
| (a: List[String]): Nothing
7+
| both match arguments ((??? : => Nothing))
8+
|
9+
| longer explanation available when compiling with `-explain`

Diff for: tests/neg/i21071.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
trait Service {
2+
def method: String
3+
}
4+
5+
object MySuite {
6+
def foo(a: List[String]) = ???
7+
def foo(a: String) = ???
8+
9+
foo { // error
10+
11+
new Service {
12+
private val underlying: Service = ???
13+
private val s = "foo"
14+
15+
export underlying.*
16+
export s.toLowerCase
17+
}
18+
19+
???
20+
}
21+
}

0 commit comments

Comments
 (0)