Skip to content

Save/restore exc_info in context manager #735

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

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Src/IronPython/Compiler/Ast/WithStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,16 @@ public override MSAst.Expression Reduce() {
// exit(None, None, None)
//******************************************************************

var previousException = Ast.Variable(typeof(Exception), "$previousException");
variables.Add(previousException);

MSAst.ParameterExpression exception;
statements.Add(
// try:
AstUtils.Try(
AstUtils.Try(// try statement body
PushLineUpdated(false, lineUpdated),
Ast.Assign(previousException, Ast.Call(AstMethods.SaveCurrentException)),
_var != null ?
(MSAst.Expression)Ast.Block(
// VAR = value
Expand All @@ -182,6 +186,7 @@ public override MSAst.Expression Reduce() {
exception,
GlobalParent.AddDebugInfoAndVoid(
Ast.Block(
Ast.Call(AstMethods.SetCurrentException, Parent.LocalContext, exception),
// exc = False
MakeAssignment(
exc,
Expand Down Expand Up @@ -216,6 +221,7 @@ public override MSAst.Expression Reduce() {
)
// finally:
).Finally(
Ast.Call(AstMethods.RestoreCurrentException, previousException),
// if exc:
// exit(None, None, None)
AstUtils.IfThen(
Expand Down
4 changes: 0 additions & 4 deletions Tests/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ def __init__(self, s):
with M1(self):
pass

# https://github.com/IronLanguages/ironpython3/issues/726
@unittest.expectedFailure
def test_with_fail(self):
"""with.__exit__ doesn't see exception in exception case."""
class M2(ManBase):
Expand Down Expand Up @@ -441,8 +439,6 @@ def __exit__(self, t, v, tb):
pass
self.A(15)

# https://github.com/IronLanguages/ironpython3/issues/726
@unittest.expectedFailure
# call 'with' from an except block, do failure case
def test_with_except_fail(self):
class M2(ManBase):
Expand Down