Skip to content

Commit 33523d1

Browse files
committed
Redo transparent overloading resolution also for Idents as refs
So far this was only done if the reference was a Select.
1 parent e486384 commit 33523d1

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

compiler/src/dotty/tools/dotc/typer/PrepareTransparent.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,27 +307,36 @@ object PrepareTransparent {
307307
}
308308

309309
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
310+
val sym = tree.symbol
310311
tree match {
311312
case Ident(nme.WILDCARD) =>
312313
case _: Ident | _: This =>
313314
//println(i"leaf: $tree at ${tree.pos}")
314-
if (tree.symbol.exists && !isLocal(tree.symbol, inlineMethod)) {
315+
if (sym.exists && !isLocal(sym, inlineMethod)) {
315316
if (ctx.debug) inlining.println(i"type at $tree @ ${tree.pos.toSynthetic} = ${tree.tpe}")
316-
typeAtPos(tree.pos.toSynthetic) = tree.tpe
317+
tree.tpe match {
318+
case tp: NamedType if tp.prefix.member(sym.name).isOverloaded =>
319+
// refer to prefix instead of to ident directly, so that overloading can be resolved
320+
// again at expansion site
321+
println(i"RECORD start for $tree")
322+
typeAtPos(tree.pos.startPos) = tp.prefix
323+
case _ =>
324+
typeAtPos(tree.pos.toSynthetic) = tree.tpe
325+
}
317326
// Note: It's possible that during traversals several types are stored under the same
318327
// position. This could happen for instance for implicit conersions added around a tree.
319328
// In general, it's always the innermost tree that holds the relevant type. The traversal
320329
// order guarantees that the innermost tree's type is stored last, and thereby replaces all previously
321330
// stored types.
322331
}
323332
case _: Select =>
324-
tree.symbol.name match {
333+
sym.name match {
325334
case InlineAccessorName(UniqueInlineName(_, _)) => return // was already recorded in Apply
326335
case InlineAccessorName(_) => registerAccessor(tree)
327336
case _ =>
328337
}
329338
case Apply(_: RefTree | _: TypeApply, receiver :: Nil) =>
330-
tree.symbol.name match {
339+
sym.name match {
331340
case InlineAccessorName(UniqueInlineName(_, _)) => registerAccessor(tree)
332341
case _ =>
333342
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
object Test {
2+
3+
def f(x: Int): Int = x
4+
def f(x: String): String = x
5+
def f(x: Any): Any = x
6+
7+
transparent def g(x: Any) = f(x)
8+
transparent def h(x: Any) = this.f(x)
9+
10+
locally {
11+
val x1 = g(1)
12+
val x2 = g("bb")
13+
val y1: Int = x1
14+
val y2: String = x2
15+
}
16+
locally {
17+
val x1 = h(1)
18+
val x2 = h("bb")
19+
val y1: Int = x1
20+
val y2: String = x2
21+
}
22+
}

0 commit comments

Comments
 (0)