Skip to content

Commit cfe3246

Browse files
committed
Fix scala#3452: Fix cycle with implicit by-name parameter
When creating a lazy val to represent an implicit by-name parameter, we need to fully define its type, otherwise cycles can arise in our constraints. This is similar to the issue fixed in eb2fdf2
1 parent 28f6c3f commit cfe3246

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ trait Implicits { self: Typer =>
617617
*/
618618
val (formalValue, lazyImplicit, argCtx) = formal match {
619619
case ExprType(fv) =>
620+
fullyDefinedType(fv, "implicit by-name parameter", pos)
620621
val lazyImplicit = ctx.newLazyImplicit(fv)
621622
(fv, lazyImplicit, lazyImplicitCtx(lazyImplicit))
622623
case _ => (formal, NoSymbol, ctx)

tests/neg/i3542.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
trait TC[A]
3+
4+
implicit def case1[F[_]](implicit t: => TC[F[Any]]): TC[String] = ???
5+
implicit def case2[G[_]](implicit r: TC[G[Any]]): TC[Int] = ???
6+
7+
implicitly[TC[Int]]
8+
}

tests/pos/i3542.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Foo[T]
2+
3+
object Test {
4+
implicit def foo[T](implicit rec: => Foo[T]): Foo[T] = ???
5+
6+
val bla: Foo[Int] = implicitly[Foo[Int]]
7+
}

0 commit comments

Comments
 (0)