getkyo / kyo

Toolkit for Scala Development
https://getkyo.io
Apache License 2.0
562 stars 47 forks source link

Type inference issue #900

Closed johnhungerford closed 8 hours ago

johnhungerford commented 9 hours ago

The compiler allows you to incorrectly annotate pending effect intersections, and the resulting effects break quietly during runtime

Minified example

import kyo.*

object Example:
  val doThing1: String < (Async & Abort[Int]) = "done"
  val doThing2: Unit < Async = doThing1.map(s => Kyo.logInfo(s))

object App extends KyoApp:
  run:
    Log.withConsoleLogger:
      Example.doThing2

App.main(Array.empty[String])

Find on scastie

Expected behavior

1) Compiler error complaining that doThing.map(s => Kyo.logInfo(s)) is not a Unit < Async but a Unit < (Async & Abort[Int]) 2) If compiler error is off the table, runtime error complaining that there is an unhandled effect somewhere. In the present case, I would expect it simply to run because the overlooked effect type Abort[Int] is never actually used (doThing1 does not actually fail).

Actual behavior

The application does not run doThing2 -- it simply returns Unit


This might be a Scala issue, ultimately, but it's become a substantial issue as I've tried to use Kyo to develop an application. I keep running into weird issues that I spend a long time debugging, only to find eventually that I've left an Abort out somewhere.

fwbrasil commented 8 hours ago

We've recently added recommended compiler flags to address this issue. The example fails to compile with the config https://scastie.scala-lang.org/HtIizca1RBumqPVIaPLgQg

johnhungerford commented 8 hours ago

Oh thank god. Just added those settings and caught about 15 issues in my project I was not aware of!

Clearly I haven't looked at the readme in a while. Thanks @fwbrasil !!