diff --git a/compiler/src/dotty/tools/dotc/transform/CheckLoopingImplicits.scala b/compiler/src/dotty/tools/dotc/transform/CheckLoopingImplicits.scala index 21b994a6d1b8..08fb103b0f1b 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckLoopingImplicits.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckLoopingImplicits.scala @@ -83,7 +83,7 @@ class CheckLoopingImplicits extends MiniPhase: checkNotLooping(t.rhs) case _ => - if sym.isOneOf(GivenOrImplicit | Lazy | ExtensionMethod) then + if sym.isOneOf(GivenOrImplicit | Lazy | ExtensionMethod) || mdef.isInstanceOf[ValDef] then checkNotLooping(mdef.rhs) mdef end transform diff --git a/tests/neg-custom-args/fatal-warnings/i14429.scala b/tests/neg-custom-args/fatal-warnings/i14429.scala new file mode 100644 index 000000000000..0460215b69c7 --- /dev/null +++ b/tests/neg-custom-args/fatal-warnings/i14429.scala @@ -0,0 +1,16 @@ +class i14429 { + val simple1: String = simple1 // error + def f: Unit = { + lazy val simple2: String = simple2 // error + } + + val simple3: String = if true then this.simple3 else "a" // error + + def firstDigitIsEven(n: Int): Boolean = if n % 10 == n then n % 2 == 0 else firstDigitIsEven(n / 10) + + val simple4: String = if firstDigitIsEven(22) then this.simple4 else "a" // ok + + val simple5: String = identity(this.simple5) // error + + val simple6: Function0[Any] = () => this.simple6 // Ok +}