Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ee10d29

Browse filesBrowse files
hauntsaninjazsol
andauthored
flush keepalives on operator assignment statements (#13144) (#13151)
This PR makes mypyc flush keepalives on operator assignment statements, to prevent accessing undefined variables in the generated C code. Fixes mypyc/mypyc#941. Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
1 parent 88c1b85 commit ee10d29
Copy full SHA for ee10d29

File tree

Expand file treeCollapse file tree

2 files changed

+13
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-0
lines changed

‎mypyc/irbuild/statement.py

Copy file name to clipboardExpand all lines: mypyc/irbuild/statement.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def transform_operator_assignment_stmt(builder: IRBuilder, stmt: OperatorAssignm
136136
# usually operator assignments are done in-place
137137
# but when target doesn't support that we need to manually assign
138138
builder.assign(target, res, res.line)
139+
builder.flush_keep_alives()
139140

140141

141142
def transform_import(builder: IRBuilder, node: Import) -> None:

‎mypyc/test-data/run-generators.test

Copy file name to clipboardExpand all lines: mypyc/test-data/run-generators.test
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,15 @@ class C:
595595
self.foo.flag = True
596596
yield
597597
self.foo.flag = False
598+
599+
[case testGeneratorEarlyReturnWithBorrows]
600+
from typing import Iterator
601+
class Bar:
602+
bar = 0
603+
class Foo:
604+
bar = Bar()
605+
def f(self) -> Iterator[int]:
606+
if self:
607+
self.bar.bar += 1
608+
return
609+
yield 0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.