Skip to content

Wrong async stacktrace #2982

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
kpodsiad opened this issue May 7, 2022 Discussed in #2981 · 3 comments
Closed

Wrong async stacktrace #2982

kpodsiad opened this issue May 7, 2022 Discussed in #2981 · 3 comments
Labels

Comments

@kpodsiad
Copy link

kpodsiad commented May 7, 2022

Discussed in #2981

Originally posted by kpodsiad May 7, 2022
The following snippet

//> using scala "2.13.8"
//> using lib "org.typelevel::cats-effect:3.3.11"

package a

import cats.effect.IOApp
import cats.effect.IO

object Main extends IOApp.Simple {
  val io = IO(5)
  val x = List()
  override def run: IO[Unit] = io
    .flatMap(_ => IO(x(5)))
    .void
}

produces following stacktrace

java.lang.IndexOutOfBoundsException: 5
        at scala.collection.LinearSeqOps.apply(LinearSeq.scala:117)
        at scala.collection.LinearSeqOps.apply$(LinearSeq.scala:114)
        at scala.collection.immutable.List.apply(List.scala:79)
        at a.Main$.$anonfun$run$2(Stacktraces.scala:13)
        at apply @ a.Main$.$anonfun$run$1(Stacktraces.scala:13)
        at apply @ a.Main$.<clinit>(Stacktraces.scala:10)
        at flatMap @ a.Main$.run(Stacktraces.scala:13)
        at void @ a.Main$.run(Stacktraces.scala:13)
        at run$ @ a.Main$.run(Stacktraces.scala:9)

at void @ a.Main$.run(Stacktraces.scala:13) looks wrong to me, shouldn't it be line 14 instead?

@armanbilge
Copy link
Member

@durban
Copy link
Contributor

durban commented Apr 24, 2023

Strangely, the original stacktrace already seems to be incorrect:

package com.example

object Bar {

  def self(x: Any): Bar.type =
    this

  def void(): Unit =
    throw new Exception

  def main(args: Array[String]): Unit = {
    this
      .self((x: Int) => x)
      .void() // this is line 14
  }
}
java.lang.Exception
        at com.example.Bar$.void(Foo.scala:9)
        at com.example.Bar$.main(Foo.scala:13)
        at com.example.Bar.main(Foo.scala)
        ...

Note 13 instead of 14.

@armanbilge
Copy link
Member

Nice find! It also affects Scala 3. I think we can say this is not our bug, and possibly not a bug at all? Let's see what the dotty team says.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants