Open robknapen opened 2 years ago
I've obtained SO too with scala cli reproduction. Problem is present when code is executed via code lense so it has to be connected with debugging.
//> using scala "3.1.3"
//> using lib "dev.zio::zio:2.0.0"
import zio._
object SumZIO extends ZIOAppDefault {
def sumZIO(n: Int): UIO[Int] =
if (n == 0) ZIO.succeed(0)
else for {
current <- ZIO.succeed(n)
prevSum <- sumZIO(n - 1)
} yield current + prevSum
override def run: Task[Unit] = for {
_ <- ZIO.succeed(println("Running"))
result <- sumZIO(20000)
_ <- ZIO.succeed(println(result))
} yield ()
}
EDIT: I was able to reproduce error using scala-cli 0.1.5 but after upgrade to 0.1.9 it works so it seems like problem existed in specific bloop version.
I can reproduce this in IntelliJ using an SBT project running this code, as long as I attach a debugger. So I think that 1. yes, it is debugger-related, and 2. may not be bloop since in IntelliJ that is going through BSP. However, when just attaching a debugger in plain SBT (no IDE) and running the app, I have no issues, so it seems to not be quite as simple as just a debugger.
EDIT: I discovered that "plain" SBT sidesteps this issue when you turn on the debugger by forcing the JVM arg -Xss4m
. Perhaps scala-cli is doing the same on later versions.
Describe the bug
Hi,
The small program below is running fine from IDEA, but causes a stack overflow exception (see the attached screenshot) when run from VSCode. This is on macOS 12.4, Apple M1 cpu, Temurin JDK 17.0.2, Scala 3.1.3, and ZIO 2.0.0. VSCode is using Metals 0.11.7. IDEA the Scala plugin version 2022.1.629.
The stack overflow also happens in VSCode with much smaller values for n (e.g. 3000), but there doesn't seem to be a consistent highest value that still can be calculated. Maybe some 'memory effect' from re-use of a JVM?
import zio._
object SumZIO extends ZIOAppDefault {
def sumZIO(n: Int): UIO[Int] = if (n == 0) ZIO.succeed(0) else for { current <- ZIO.succeed(n) prevSum <- sumZIO(n - 1) } yield current + prevSum
override def run: Task[Unit] = for { <- ZIO.succeed(println("Running")) result <- sumZIO(20000) <- ZIO.succeed(println(result)) } yield ()
}
Expected behavior
I would expect more similar behaviour of the (compiled) code.
Operating system
macOS
Editor/Extension
VS Code
Version of Metals
v0.11.7
Extra context or search terms
Also submitted this as issue for ZIO, but the code compiles and runs so might be Metals related.
See: https://github.com/zio/zio/issues/7058