-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve s.u.Using
suppression order
#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 = 42 After: ...
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
Change
scala.util.Using
to havescala.util.control.ControlThrowable
be suppressed by non-fatalexceptions (
scala.util.control.NonFatal
).Fixes scala/bug#13088