Skip to content

force compile error of discarded defer block - #1202

Merged
hearnadam merged 6 commits into
getkyo:mainfrom
ahoy-jon:detectDeferUnit
May 23, 2025
Merged

hearnadam merged 6 commits into
getkyo:mainfrom
ahoy-jon:detectDeferUnit

Conversation

@ahoy-jon

Copy link
Copy Markdown
Collaborator

#903

Problem

Due to scala/scala3#23018, some defer block are silently transforming from

val oups:Int < Abort[String] = Abort.fail("oups")

val x : Unit < Any = {
  defer:
    oups.now + 1
}

to

val x: Unit < Any = {
  //discard
  kernel.`<`.lift(())
}

without any warning.

Solution

make the compilation fail if we try to lift Unit < A into Unit < B without B <:< A.

@ahoy-jon
ahoy-jon requested a review from hearnadam May 23, 2025 23:03
@ahoy-jon

Copy link
Copy Markdown
Collaborator Author

@hearnadam fixed a couple of small stuffs (private, ...).

@ahoy-jon

Copy link
Copy Markdown
Collaborator Author

it's good, it finds errors: 🥳

[error] -- Error: /Users/jon/Documents/GitHub/kyo/kyo-examples/jvm/src/main/scala/examples/ledger/db/Log.scala:42:71 
[error] 42 |        private[Log] def flushLoop(interval: Duration): Unit < Async = defer {
[error]    |                                                                       ^
[error]    |Cannot lift `Unit < kyo.Async$package.Async & kyo.Abort[kyo.Closed]` to the expected type (`Unit < ?`).
[error]    |This may be due to an effect type mismatch.
[error]    |Consider removing or adjusting the type constraint on the left-hand side.
[error]    |More info : https://github.com/getkyo/kyo/issues/903
[error] 43 |            Async.sleep(interval).now
[error] 44 |            val entries = q.drain.now
[error] 45 |            append(entries).now
[error] 46 |            flushLoop(interval).now
[error] 47 |        }

@hearnadam
hearnadam merged commit c7a56aa into getkyo:main May 23, 2025
@ahoy-jon
ahoy-jon deleted the detectDeferUnit branch May 24, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants