10000 Improve `s.u.Using` suppression order · scala/scala@312dcf4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 312dcf4

Browse files
committed
Improve s.u.Using suppression order
Change `scala.util.Using` to have `scala.util.control.ControlThrowable` be suppressed by non-fatal exceptions (`scala.util.control.NonFatal`).
1 parent fd9f761 commit 312dcf4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/library/scala/util/Using.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ import scala.util.control.{ControlThrowable, NonFatal}
125125
* - `java.lang.LinkageError`
126126
* - `java.lang.InterruptedException` and `java.lang.ThreadDeath`
127127
* - [[scala.util.control.NonFatal fatal exceptions]], excluding `scala.util.control.ControlThrowable`
128+
* - all other exceptions, excluding `scala.util.control.ControlThrowable`
128129
* - `scala.util.control.ControlThrowable`
129-
* - all other exceptions
130130
*
131131
* When more than two exceptions are thrown, the first two are combined and
132132
* re-thrown as described above, and each successive exception thrown is combined
@@ -265,9 +265,9 @@ object Using {
265265
case _: VirtualMachineError => 4
266266
case _: LinkageError => 3
267267
case _: InterruptedException | _: ThreadDeath => 2
268-
case _: ControlThrowable => 0
268+
case _: ControlThrowable => -1 // below everything
269269
case e if !NonFatal(e) => 1 // in case this method gets out of sync with NonFatal
270-
case _ => -1
270+
case _ => 0
271271
}
272272
@inline def suppress(t: Throwable, suppressed: Throwable): Throwable = { t.addSuppressed(suppressed); t }
273273

test/junit/scala/util/UsingTest.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class UsingTest {
8282
onLinkage = IsSuppressed,
8383
onInterruption = IsSuppressed,
8484
onControl = IsSuppressed,
85-
onException = IgnoresSuppressed)
85+
onException = IsSuppressed)
8686
}
8787

8888
@Test
@@ -91,7 +91,7 @@ class UsingTest {
9191
new ErrorResource,
9292
onLinkage = IsSuppressed,
9393
onInterruption = IsSuppressed,
94-
onControl = IsSuppressed,
94+
onControl = AcceptsSuppressed,
9595
onException = IsSuppressed)
9696
}
9797

@@ -101,7 +101,7 @@ class UsingTest {
101101
new ExceptionResource,
102102
onLinkage = IsSuppressed,
103103
onInterruption = IsSuppressed,
104-
onControl = IsSuppressed,
104+
onControl = AcceptsSuppressed,
105105
onException = IsSuppressed)
106106
}
107107

@@ -135,7 +135,7 @@ class UsingTest {
135135
check(new UsingVMError(_), behavior = IsSuppressed, allowsSuppression = true, yieldsTry = false)
136136
check(new UsingLinkageError(_), onLinkage, allowsSuppression = true, yieldsTry = false)
137137
check(_ => new UsingInterruption, onInterruption, allowsSuppression = true, yieldsTry = false)
138-
check(new UsingControl(_), onControl, allowsSuppression = false, yieldsTry = false)
138+
check(new UsingControl(_), onControl, allowsSuppression = false, yieldsTry = onControl == IsSuppressed)
139139
check(new UsingError(_), onException, allowsSuppression = true, yieldsTry = onException == IsSuppressed)
140140
check(new UsingException(_), onException, allowsSuppression = true, yieldsTry = onException == IsSuppressed)
141141
}
@@ -177,7 +177,7 @@ class UsingTest {
177177
onLinkage = IsSuppressed,
178178
onInterruption = IsSuppressed,
179179
onControl = IsSuppressed,
180-
onException = IgnoresSuppressed)
180+
onException = IsSuppressed)
181181
}
182182

183183
@Test
@@ -186,7 +186,7 @@ class UsingTest {
186186
new ErrorResource,
187187
onLinkage = IsSuppressed,
188188
onInterruption = IsSuppressed,
189-
onControl = IsSuppressed,
189+
onControl = AcceptsSuppressed,
190190
onException = IsSuppressed)
191191
}
192192

@@ -196,7 +196,7 @@ class UsingTest {
196196
new ExceptionResource,
197197
onLinkage = IsSuppressed,
198198
onInterruption = IsSuppressed,
199-
onControl = IsSuppressed,
199+
onControl = AcceptsSuppressed,
200200
onException = IsSuppressed)
201201
}
202202

@@ -230,7 +230,7 @@ class UsingTest {
230230
check(new UsingVMError(_), behavior = IsSuppressed, allowsSuppression = true, yieldsTry = false)
231231
check(new UsingLinkageError(_), onLinkage, allowsSuppression = true, yieldsTry = false)
232232
check(_ => new UsingInterruption, onInterruption, allowsSuppression = true, yieldsTry = false)
233-
check(new UsingControl(_), onControl, allowsSuppression = false, yieldsTry = false)
233+
check(new UsingControl(_), onControl, allowsSuppression = false, yieldsTry = onControl == IsSuppressed)
234234
check(new UsingError(_), onException, allowsSuppression = true, yieldsTry = onException == IsSuppressed)
235235
check(new UsingException(_), onException, allowsSuppression = true, yieldsTry = onException == IsSuppressed)
236236
}
@@ -272,7 +272,7 @@ class UsingTest {
272272
onLinkage = IsSuppressed,
273273
onInterruption = IsSuppressed,
274274
onControl = IsSuppressed,
275-
onException = IgnoresSuppressed)
275+
onException = IsSuppressed)
276276
}
277277

278278
@Test
@@ -281,7 +281,7 @@ class UsingTest {
281281
new ErrorResource,
282282
onLinkage = IsSuppressed,
283283
onInterruption = IsSuppressed,
284-
onControl = IsSuppressed,
284+
onControl = AcceptsSuppressed,
285285
onException = IsSuppressed)
286286
}
287287

@@ -291,7 +291,7 @@ class UsingTest {
291291
new ExceptionResource,
292292
onLinkage = IsSuppressed,
293293
onInterruption = IsSuppressed,
294-
onControl = IsSuppressed,
294+
onControl = AcceptsSuppressed,
295295
onException = IsSuppressed)
296296
}
297297

0 commit comments

Comments
 (0)
0