Skip to content

Commit ee10d29

Browse 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 <[email protected]>
1 parent 88c1b85 commit ee10d29

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mypyc/irbuild/statement.py

+1
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

+12
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)