Skip to content
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

Fix issue #4002 #4003

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits {
lift(k(resume)) flatMap {
case Right(a) => G.pure(a)
case Left(Some(fin)) => G.onCancel(poll(get), lift(fin))
case Left(None) => poll(get)
case Left(None) => get
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause the same kind of semantic break as the async_ change in 3.5.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

As far as I can tell, asyncCheckAttempt should have been added like this in 3.5.0 (and for Async, it was). It's only due to an unlucky git merge that it wasn't. (And I guess due to the lack of a unit test.)

Copy link
Member

@djspiewak djspiewak Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect the impact of this is much lower than the async_ change, since this is a far less widely used constructor. Also we override the Async implementation in Async[IO], so this bug fix is actually entirely shadowed unless you're using monad transformers or a third-party effect. I think it's fair to consider this PR to be a bug fix rather than a breaking change.

Edit: Oh my shadowing argument is backwards. Rip. Either way, bug fix IMO.

}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/shared/src/test/scala/cats/effect/IOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,17 @@ class IOSpec extends BaseSpec with Discipline with IOPlatformSpecification {
outerR mustEqual 1
innerR mustEqual 2
}

"be uncancelable if None finalizer" in ticked { implicit ticker =>
val t = IO.asyncCheckAttempt[Int] { _ => IO.pure(Left(None)) }
val test = for {
fib <- t.start
_ <- IO(ticker.ctx.tick())
_ <- fib.cancel
} yield ()

test must nonTerminate
}
}

"async" should {
Expand Down
Loading