- Notifications
You must be signed in to change notification settings - Fork 1.1k
Safer exceptions #11721
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
Safer exceptions #11721
Conversation
0228129 to fe446b4 Compare
Actually, no. The rules for context function types make them mutually compatible. I am not yet sure about unions, whether there is a way to obtain them. But since we do have commutativity, maybe they are not needed. |
c02fb16 to 1c353ab Compare | import language.experimental.erasedTerms | ||
| import annotation.implicitNotFound | ||
| | ||
| /** A ability class that allows to throw exception `E`. When used with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** AN ability ..
though, in other places it is referenced as "A capability"..
| Would it be possible for a user to implement something like this, without needing casts or other hacks? object Try: def apply[E, A](body: CanThrow[E] ?=> A): Try[A] = try Success(body) catch case NonFatal(ex) => Failure(ex) |
| I would like to suggest, to consider rename |
1c353ab to b3b3efb Compare | It fails the binary compatibility check: scala3-library-bootstrapped: Failed binary compatibility check against org.scala-lang:scala3-library_3:3.0.0! Found 7 potential problems (filtered 26) Error: * interface scala.CanThrow does not have a correspondent in other version Error: filter with: ProblemFilters.exclude[MissingClassProblem]("scala.CanThrow") ...How should this be addressed? |
| You'll have to mark it as experimental, and then add an exception for MiMa justified by the fact that it is experimental. |
| @sjrd In this case it's probably OK to mark it as experimental. But in general there could be additions that are slated for the next minor release. in this case we do want them to pass the CR without adding @experimental and without fiddling with Mima. How do we achieve that? |
As I said in #12778, there should be a (simple) way to tune the build such that MiMa constraints would be relaxed. Just reading at the source code, it seems to me that setting Edit: sorry my suggestion applies only to PRs that target the next minor release, not to experimental features. |
1d42a72 to 471f19d Compare 471f19d to fe50890 Compare 6285368 to a2ebf00 Compare | I have changed |
| I opened an issue #13392. |
There are two distinct issues here.
|
d1cb9de to 542d525 Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to make CanThrow compile before #13392 is fixed, just disable the check on the library by removing this line https://github.com/lampepfl/dotty/blob/master/project/Build.scala#L1746. Do not add #13396 to this PR as it has it too controvertial at this time.
| Blocked by #13404 |
What I meant is that we can disable that check for this PR to be able to merge it before #13392 is fixed. Then reenable the check when we fix #13392 (before 3.1). |
| Not if it is the wrong fix |
Introduce a flexible scheme for declaring and checking which exceptions can be thrown. It relies on the effects as implicit capabilities pattern. The scheme is not 100% safe yet since it does not track and prevent capability capture. Nevertheless, it's already useful for declaring thrown exceptions and finding mismatches between provided and required capabilities.
... instead of "ability". Two reasons: - it's more standard - it's also more correct. According to https://writingexplained.org/capability-vs-ability-difference#When_to_Use_Capability a capability is a yes or no proposition, whereas an ability is a matter of degree.
- Move $throws to scala.runtime - Add comment
78d64c0 to adb06f9 Compare | Rebased to make use of #13394 for allowing erased classes |
adb06f9 to 9b35e0b Compare | Is there any chance of easing throwing multiple exceptions with a type takes a tuple of exceptions? Maybe something like infix type throwsMulti[R, T <: Tuple] = T match { case EmptyTuple => R case e *: t => throwsMulti[CanThrow[e] ?=> R, t] }? |
| Why is the example in the docs infinite recursion? def f(x: Double): Double = if x < limit then x * x else throw LimitExceeded())
|
| sorry; forget my comment above -- I just realized that I was looking at the old version. |
Introduce a flexible scheme for declaring and checking which exceptions can be thrown.
It relies on the effects as implicit capabilities pattern.
The scheme is not 100% safe yet since it does not track and prevent capability capture.
Nevertheless, it's already useful for declaring thrown exceptions and finding mismatches
between provided and required capabilities.
Link to Doc page
Everything is enabled under
Based on #11695
For Release Notes:
Safer exceptions
A new experimental feature that allows declaring and checking which exceptions can be thrown.
It relies on the effects as implicit capabilities pattern.