-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #856: Handle try/catch cases as catch cases if possible. #1315
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
Review by @DarkDimius |
9a7df53
to
8e82089
Compare
|
||
/** Is this pattern node a catch-all or type-test pattern? */ | ||
private def isCatchCase(cdef: CaseDef)(implicit ctx: Context): Boolean = cdef match { | ||
case CaseDef(Typed(Ident(nme.WILDCARD), tpt), _, _) => isSimpleThrowable(tpt.tpe) |
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.
what about guards? Since this PR they will not be desugared by patmat, and will reach the backend and be ignored there.
@nicolasstucki please ping me when ready for next review round. Thanks. |
* try { <code> } | ||
* catch { | ||
* <tryCases> // Cases that can be handled by catch | ||
* <paterMatchCases> // Cases starting with first one that can't be handled by catch |
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.
Typo: patternMatchCases
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.
Oh, same elsewhere, so I guess it's not a typo but intentional, still seems a bit weird
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.
It was indeed a typo. Must have copy pasted it around.
a48f1df
to
bcda17d
Compare
@DarkDimius this PR is ready for another round of review. |
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match { | ||
case Try(_, cases, _) => | ||
cases.foreach { | ||
case CaseDef(Typed(_, _), guard, _) => assert(guard.isEmpty, "Try case should not a guard.") |
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.
A synonym of have
is missing. Same on the next line.
Previously they were all lifted into a match with the came cases. Now the first cases are handled directly by by the catch. If one of the cases can not be handled the old scheme is applied to to it and all subsequent cases.
bcda17d
to
b0ebe6a
Compare
LGTM, Thanks! |
Previously they were all lifted into a match with the came cases.
Now the first cases are handled directly by by the catch. If one
of the cases can not be handled the old scheme is applied to to it
and all subsequent cases.