Skip to content

Fixed Missing warning for invalid recursive val #14598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is | Lazy still needed? Aren't all lazy values ValDefs?

checkNotLooping(mdef.rhs)
mdef
end transform
Expand Down
16 changes: 16 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i14429.scala
Original file line number Diff line number Diff line change
@@ -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
}