-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve scala.util.Using suppression order (NonFatal suppresses ControlThrowable)
#11000
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
Conversation
d9a208f to
4169aa1
Compare
|
Probably you didn't anticipate such far-reaching effects! |
|
I'll fix Jenkins. GHA says
|
|
Here's an example that changes semantics. Is that a good change? Before: scala> def h(s: String): Unit = throw new RuntimeException
scala> def t: Int = util.Using.resource("hai")(s => return 42)(h)
scala> t
val res0: Int = 42After: ...
scala> t
java.lang.RuntimeException
at h(<console>:1)
at $anonfun$t$2(<console>:1)
at scala.util.Using$.resource(Using.scala:304)
at t(<console>:1)
... 30 elided
Suppressed: scala.runtime.NonLocalReturnControl$mcI$sp@som-snytt I don't follow your m |
I would argue that not only is it a good change, it is a correct change. before the change, where did the I'll have a look at the failing tests Soon™. I admittedly did not run them locally, and just kinda assumed I adjusted them correctly |
|
In the example, we want the happy path. If I want to "handle all the possibilities", then I have to catch all the possible aborts. The answer for Future is use UEH so exceptions don't "disappear". |
|
Java: jshell> public int f() throws Exception { try (Closeable c = () -> { throw new RuntimeException(); }) { return 42; } }
| modified method f()
jshell> f()
| Exception java.lang.RuntimeException
| at lambda$f$0 (#3:1)
| at f (#3:1)
| at (#4:1) |
|
The Odersky Rule is promulgated at |
Ergonomics in repl could be improved. |
|
The new behavior is correct, I think: if you throw an exception while closing the resource, you did not successfully use the resource. However, non-local return is deprecated, and Therefore, I am not convinced that there's much benefit to changing |
4169aa1 to
312dcf4
Compare
|
... so we cannot fix |
personally, I think this PR is a bug fix. the previous/current behaviour is wrong I believe because I (and everyone else) didn't think about it particularly hard past "fatal should have priority", not because we explicitly decided that also, sorry for taking so long to fix the tests. life happened at me |
We could (by intercepting the type of exception that they throw and handling them specially), but since And then if you want exception handling that allows control flow to cross, you use a library for that. |
|
I don't think this PR changes anything meaningful wrt |
Thanks, that makes sense :-/ |
Change `scala.util.Using` to have `scala.util.control.ControlThrowable` be suppressed by non-fatal exceptions (`scala.util.control.NonFatal`).
|
thanks for squashing for me Lukas! |
|
Thank you for the work! |
Improve `s.u.Using` suppression order
Improve `s.u.Using` suppression order
s.u.Using suppression orderscala.util.Using suppression order (NonFatal suppresses ControlThrowable)
|
ported to scala-collection-compat in scala/scala-collection-compat#712 |
…n-compat to v2.14.0 (java17) (#3298) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [org.scala-lang.modules:scala-collection-compat](http://www.scala-lang.org/) ([source](https://redirect.github.com/scala/scala-collection-compat)) | minor | `2.13.0` -> `2.14.0` | --- ### Release Notes <details> <summary>scala/scala-collection-compat (org.scala-lang.modules:scala-collection-compat)</summary> ### [`v2.14.0`](https://redirect.github.com/scala/scala-collection-compat/releases/tag/v2.14.0): 2.14.0 [Compare Source](https://redirect.github.com/scala/scala-collection-compat/compare/v2.13.0...v2.14.0) Because the behavior of `Using` has changed, `Using` users should adopt this release in tandem with upgrading to Scala 2.13.17. If your crossbuild also includes Scala 3, then you may wish to also wait for a Scala 3 release that has itself taken the upgrade to the 2.13.17 standard library, so your entire CI matrix will get the same behavior. #### Breaking changes - update `Using` from Scala 2.13.17 in [#​712](https://redirect.github.com/scala/scala-collection-compat/pull/712) - the behavior change is explained at [scala/scala#11000](https://redirect.github.com/scala/scala/pull/11000) by [@​NthPortal](https://redirect.github.com/NthPortal) #### Chores - update scala-native to 0.5.6 by [@​xuwei-k](https://redirect.github.com/xuwei-k) in [#​682](https://redirect.github.com/scala/scala-collection-compat/pull/682) - Update sbt, scripted-plugin to 1.10.10 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​688](https://redirect.github.com/scala/scala-collection-compat/pull/688) - Update sbt, scripted-plugin to 1.10.11 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​691](https://redirect.github.com/scala/scala-collection-compat/pull/691) - Update sbt, scripted-plugin to 1.11.0 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​697](https://redirect.github.com/scala/scala-collection-compat/pull/697) - Update sbt, scripted-plugin to 1.11.1 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​699](https://redirect.github.com/scala/scala-collection-compat/pull/699) - Update sbt, scripted-plugin to 1.11.2 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​701](https://redirect.github.com/scala/scala-collection-compat/pull/701) - Update sbt, scripted-plugin to 1.11.3 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​703](https://redirect.github.com/scala/scala-collection-compat/pull/703) - Update sbt, scripted-plugin to 1.11.4 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​705](https://redirect.github.com/scala/scala-collection-compat/pull/705) - Update sbt, scripted-plugin to 1.11.5 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​706](https://redirect.github.com/scala/scala-collection-compat/pull/706) - Update sbt, scripted-plugin to 1.11.6 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​707](https://redirect.github.com/scala/scala-collection-compat/pull/707) - Update sbt, scripted-plugin to 1.11.7 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​713](https://redirect.github.com/scala/scala-collection-compat/pull/713) - Update sbt-scala-module to 3.3.0 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​700](https://redirect.github.com/scala/scala-collection-compat/pull/700) - Update scala3-library\_sjs1 to 3.3.5 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​681](https://redirect.github.com/scala/scala-collection-compat/pull/681) - Update scala3-library\_sjs1 to 3.3.6 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​696](https://redirect.github.com/scala/scala-collection-compat/pull/696) - Update scalafmt-core to 3.9.0 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​683](https://redirect.github.com/scala/scala-collection-compat/pull/683) - Update scalafmt-core to 3.9.1 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​685](https://redirect.github.com/scala/scala-collection-compat/pull/685) - Update scalafmt-core to 3.9.10 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​708](https://redirect.github.com/scala/scala-collection-compat/pull/708) - Update scalafmt-core to 3.9.2 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​686](https://redirect.github.com/scala/scala-collection-compat/pull/686) - Update scalafmt-core to 3.9.3 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​689](https://redirect.github.com/scala/scala-collection-compat/pull/689) - Update scalafmt-core to 3.9.4 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​690](https://redirect.github.com/scala/scala-collection-compat/pull/690) - Update scalafmt-core to 3.9.5 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​693](https://redirect.github.com/scala/scala-collection-compat/pull/693) - Update scalafmt-core to 3.9.6 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​694](https://redirect.github.com/scala/scala-collection-compat/pull/694) - Update scalafmt-core to 3.9.7 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​698](https://redirect.github.com/scala/scala-collection-compat/pull/698) - Update scalafmt-core to 3.9.8 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​702](https://redirect.github.com/scala/scala-collection-compat/pull/702) - Update scalafmt-core to 3.9.9 by [@​scala-steward](https://redirect.github.com/scala-steward) in [#​704](https://redirect.github.com/scala/scala-collection-compat/pull/704) - Add `dependabot.yml` for GitHub Actions update by [@​xuwei-k](https://redirect.github.com/xuwei-k) in [#​709](https://redirect.github.com/scala/scala-collection-compat/pull/709) - Bump actions/checkout from 2 to 5 by [@​dependabot](https://redirect.github.com/dependabot)\[bot] in [#​711](https://redirect.github.com/scala/scala-collection-compat/pull/711) - Bump actions/setup-java from 2 to 5 by [@​dependabot](https://redirect.github.com/dependabot)\[bot] in [#​710](https://redirect.github.com/scala/scala-collection-compat/pull/710) - readme tweaks by [@​SethTisue](https://redirect.github.com/SethTisue) in [#​680](https://redirect.github.com/scala/scala-collection-compat/pull/680) #### New Contributors - [@​dependabot](https://redirect.github.com/dependabot)\[bot] made their first contribution in [#​710](https://redirect.github.com/scala/scala-collection-compat/pull/710) **Full Changelog**: <scala/scala-collection-compat@v2.13.0...v2.14.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/slick/slick). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNDMuMSIsInVwZGF0ZWRJblZlciI6IjQxLjE0My4xIiwidGFyZ2V0QnJhbmNoIjoiamF2YTE3IiwibGFiZWxzIjpbXX0=-->
### What changes were proposed in this pull request? Upgrade to scala 2.13.17 ### Why are the changes needed? To bring the latest bug fixes and improvements like JDK 25 support. Note that Scala community announces two breaking changes due to the bug fixes. > Breaking changes > - Mix in the productPrefix hash statically in case class hashCode > - Improve scala.util.Using suppression order - https://github.com/scala/scala/releases/tag/v2.13.17 - scala/scala#11046 - scala/scala#10937 - scala/scala#10927 - scala/bug#13058 - scala/scala#11023 - scala/bug#13033 - scala/scala#11000 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? local and github builds ### Was this patch authored or co-authored using generative AI tooling? No Closes #52509 from vrozov/SPARK-53585. Authored-by: Vlad Rozov <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
### What changes were proposed in this pull request? Upgrade to scala 2.13.17 ### Why are the changes needed? To bring the latest bug fixes and improvements like JDK 25 support. Note that Scala community announces two breaking changes due to the bug fixes. > Breaking changes > - Mix in the productPrefix hash statically in case class hashCode > - Improve scala.util.Using suppression order - https://github.com/scala/scala/releases/tag/v2.13.17 - scala/scala#11046 - scala/scala#10937 - scala/scala#10927 - scala/bug#13058 - scala/scala#11023 - scala/bug#13033 - scala/scala#11000 ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? local and github builds ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#52509 from vrozov/SPARK-53585. Authored-by: Vlad Rozov <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
In
scala.util.Using, when two exceptions are thrown, one is attached to the other usingaddSuppressedaccording to a specified order.
Change that order to have
scala.util.control.ControlThrowablesuppressed by non-fatal exceptions (scala.util.control.NonFatal).Fixes scala/bug#13088
Users of scala-collection-compat can upgrade to 2.14.0 to get the same behavior change
If you use
Usingin a project that crossbuilds to Scala 3, you may wish to wait for a Scala 3 release that includes the 2.13.17 standard library, or use a dependency override to force the upgrade in your build