Skip to content

[BUG]: Runtime Exception with unexpected pending effects #1443

@Tylerwbrown

Description

@Tylerwbrown

Version

1.0-RC1

Scala Version

3.7.4

Expected Behavior

The types are inferred correctly (e.g not to nothing), or I get a compiler error if they cannot be inferred.

Adding this bug report because the runtime told me to lol

Actual Behavior

The final type is inferred as Result[Nothing, Int] < Any when it should be Result[String, Int] < Async, and produced the following runtime exception:

[info] running Main
[error] kyo.bug$KyoBugException: BUG Unexpected pending eff
[error]         at kyo.bug$KyoBugException$.apply(data.scal
[error]         at kyo.bug$.apply(data.scala:26)
[error]         at kyo.kernel$package$.failTag(kernel.scala
[error]         at kyo.kernel.Pending$package$$less$.inline
[error]         at kyo.Sync$package$Sync$Unsafe$.evalLoop$1
[error]         at kyo.Sync$package$Sync$Unsafe$.evalOrThrow(Sync.scala:140)
[error]         at kyo.KyoAppPlatformSpecific.run$$anonfun$1(KyoAppPlatformSpecific.scala:8)
[error]         at kyo.KyoApp$.kyo$KyoApp$Base$$_$main$$anonfun$1(KyoApp.scala:83)
[error]         at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error]         at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error]         at kyo.Chunk.flush$1(Chunk.scala:431)
[error]         at kyo.Chunk.foreach(Chunk.scala:434)
[error]         at kyo.KyoApp$Base.main(KyoApp.scala:83)
[error]         at Main.main(Simple.scala)
[error]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[error]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error]         at java.base/java.lang.reflect.Method.invoke(Method.java:569)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) kyo.bug$KyoBugException: BUG Unexpected pending effect while handling scala.Any: Kyo(kyo.Abort[-scala.Any], Input(Failure(4something)), Simple.scala:21:68, l)(Env.run(f2Impl)(Abort.run(fn(4, "something"))))) Please open an issue 🥹 https://github.com/getkyo/kyo/issues

Steps to Reproduce

import kyo.*

type F1[S] = (Int, String) => String < S
type F2[S] = String => Int < S

def f1Impl(num: Int, str: String): String < Async = num.toString + str
def f2Impl(str: String): Int < Abort[String] = str.toIntOption match
  case Some(num) => num
  case None => Abort.fail(str)

def fn[S](num: Int, str: String) =
  for
    str <- Env.use[F1[S]](_(num, str))
    res <- Env.use[F2[S]](_(str))
  yield res

object Main extends KyoApp:
  run:
    Env.run(f1Impl)(Env.run(f2Impl)(Abort.run(fn(4, "something"))))

Current Workaround

Add a type annotation for fn. This also allows me to use handle the way I want to:

fn[Async & Abort[String]](4, "something")
  .handle(Env.run(f1Impl), Env.run(f2Impl), Abort.run)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions