question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing warning for invalid recursive val.

See original GitHub issue

Compiler version

3.1.1

Minimized code

val a: Int = a

https://scastie.scala-lang.org/9Naw4C8JRuKQtPd0VXBXLw

No warnings or compilation errors

Expectation

Compiler error or warning. Scala 2 gives value a in object Playground does nothing other than call itself recursively

Without warning, this is easy to create bugs like this. For eg:

 def create[F[_], S](using enc: Encoder[S])(state: S, fsm: FSM[F, S, Cmd, Option[Stat]]) =
    new Stat[F]:
      val state = state
      val fsm   = fsm

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
liufengyuncommented, Feb 8, 2022

Asking the obvious, why isn’t -Ysafe-init a default?

There is still something we want to improve, in particular, better error messages for handling inner classes, and improve the modularity of the check (warn for subtle initialization behavior of open class/traits).

And we also want to get more community feedback before turning it on by default.

1reaction
mbovelcommented, Feb 8, 2022

Excellent, indeed:

28 |  val y: Int = y
   |      ^
   |      Access non-initialized value y. Calling trace:
   |       -> val y: Int = y    [ <...>.scala:28 ]

it’s still a good idea to have an additional check for such cases that are enabled by default.

Is it? Shouldn’t we encourage users interested in these checks to use -Ysafe-init instead, as it is a way more robust and powerful alternative to the shallow checks we could add by default?

@Swoorup could you use this flag for your use-cases?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing recursion alert · Issue #11614 · scala/bug - GitHub
Self-recursive and self-explanatory: scala> val x: Int = x ^ warning: value x does nothing other than call itself recursively x: Int =...
Read more >
return not exiting recursive method as expected - C# - Stack ...
I've got a recursive method creating a Collatz sequence (using as recursion practice) However once my method reaches the requirements for exit I ......
Read more >
Recursion and stack - The Modern JavaScript Tutorial
Loop for(val of Object.values(obj)) to iterate over object values: Object.values returns an array of them. Recursive structures. A recursive ...
Read more >
How to Fix the R Error: missing value where true/false needed
The fix for this error is quite simple. All you need to do embed your “if statement” or “while statement” in another “if...
Read more >
ISPF messages starting with ISP - IBM
Previous "cccccccc" tag attribute was missing or not valid. ... Recursion error - Recursive use of an ISPF function ( aaaaaaaa ) is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found