Skip to content

Commit 9a50c1f

Browse files
committed
Don't look for loops in rhs of lazy vals
1 parent becd554 commit 9a50c1f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/transform/CheckLoopingImplicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class CheckLoopingImplicits extends MiniPhase:
7171
case SeqLiteral(elems, _) =>
7272
elems.foreach(checkNotLooping)
7373
case t: ValDef =>
74-
checkNotLooping(t.rhs)
74+
if !t.symbol.is(Lazy) then checkNotLooping(t.rhs)
7575
case _ =>
7676

7777
if sym.isOneOf(GivenOrImplicit) then

tests/neg-custom-args/fatal-warnings/i13542.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,19 @@ val x4 =
3232
repIdentity(bar.toFoo) // error
3333
val foo: Foo = Bar(1)
3434

35+
val x5 =
36+
implicit def barToFoo4(bar: Bar): Foo =
37+
val y = bar.toFoo // error
38+
y
39+
val foo: Foo = Bar(1)
40+
41+
val x6 =
42+
implicit def barToFoo4(bar: Bar): Foo =
43+
lazy val y = bar.toFoo // OK
44+
if false then y else ???
45+
val foo: Foo = Bar(1)
46+
47+
48+
3549

3650

0 commit comments

Comments
 (0)