Skip to content

Commit 3ec0b67

Browse files
committed
Fix #3585: Add missing changeOwner when building lazy implicits
1 parent 2164c42 commit 3ec0b67

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,9 @@ trait Implicits { self: Typer =>
635635
case _ => false
636636
}
637637
if (lazyImplicit.exists && refersToLazyImplicit)
638-
Block(ValDef(lazyImplicit.asTerm, arg).withPos(pos) :: Nil, ref(lazyImplicit))
638+
Block(
639+
ValDef(lazyImplicit.asTerm, arg.changeOwner(ctx.owner, lazyImplicit)).withPos(pos) :: Nil,
640+
ref(lazyImplicit))
639641
else
640642
arg
641643
case fail @ SearchFailure(tree) =>

tests/pos/i3585.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Foo[T]
2+
3+
object Foo {
4+
implicit def pair[T, U]
5+
(implicit
6+
fooT: => Foo[(T, U)],
7+
fooU: => Foo[(U, T)]
8+
): Foo[(T, U)] = ???
9+
10+
implicit def int: Foo[Int] = ???
11+
implicit def string: Foo[String] = ???
12+
}
13+
14+
object Test extends App {
15+
implicitly[Foo[(Int, String)]]
16+
}

0 commit comments

Comments
 (0)