Commit 6a3711d2 authored by Stefan Behnel's avatar Stefan Behnel

update temp ref expression after analyse_types() if node was replaced

parent 5eab4419
...@@ -155,6 +155,11 @@ class ResultRefNode(AtomicExprNode): ...@@ -155,6 +155,11 @@ class ResultRefNode(AtomicExprNode):
else: else:
return () return ()
def update_expression(self, expression):
self.expression = expression
if hasattr(expression, "type"):
self.type = expression.type
def analyse_types(self, env): def analyse_types(self, env):
if self.expression is not None: if self.expression is not None:
self.type = self.expression.type self.type = self.expression.type
...@@ -256,6 +261,7 @@ class LetNodeMixin: ...@@ -256,6 +261,7 @@ class LetNodeMixin:
code.put_decref_clear(self.temp, self.temp_type) code.put_decref_clear(self.temp, self.temp_type)
code.funcstate.release_temp(self.temp) code.funcstate.release_temp(self.temp)
class EvalWithTempExprNode(ExprNodes.ExprNode, LetNodeMixin): class EvalWithTempExprNode(ExprNodes.ExprNode, LetNodeMixin):
# A wrapper around a subexpression that moves an expression into a # A wrapper around a subexpression that moves an expression into a
# temp variable and provides it to the subexpression. # temp variable and provides it to the subexpression.
...@@ -277,6 +283,7 @@ class EvalWithTempExprNode(ExprNodes.ExprNode, LetNodeMixin): ...@@ -277,6 +283,7 @@ class EvalWithTempExprNode(ExprNodes.ExprNode, LetNodeMixin):
def analyse_types(self, env): def analyse_types(self, env):
self.temp_expression = self.temp_expression.analyse_types(env) self.temp_expression = self.temp_expression.analyse_types(env)
self.lazy_temp.update_expression(self.temp_expression) # overwrite in case it changed
self.subexpression = self.subexpression.analyse_types(env) self.subexpression = self.subexpression.analyse_types(env)
self.type = self.subexpression.type self.type = self.subexpression.type
return self return self
...@@ -292,8 +299,10 @@ class EvalWithTempExprNode(ExprNodes.ExprNode, LetNodeMixin): ...@@ -292,8 +299,10 @@ class EvalWithTempExprNode(ExprNodes.ExprNode, LetNodeMixin):
self.subexpression.generate_evaluation_code(code) self.subexpression.generate_evaluation_code(code)
self.teardown_temp_expr(code) self.teardown_temp_expr(code)
LetRefNode = ResultRefNode LetRefNode = ResultRefNode
class LetNode(Nodes.StatNode, LetNodeMixin): class LetNode(Nodes.StatNode, LetNodeMixin):
# Implements a local temporary variable scope. Imagine this # Implements a local temporary variable scope. Imagine this
# syntax being present: # syntax being present:
......
...@@ -1022,3 +1022,14 @@ def test_cpython_offbyone_issue_23349(): ...@@ -1022,3 +1022,14 @@ def test_cpython_offbyone_issue_23349():
cdef unsigned char[:] v = bytearray(b"testing") cdef unsigned char[:] v = bytearray(b"testing")
# the following returns 'estingt' without the workaround # the following returns 'estingt' without the workaround
return bytearray(v).decode('ascii') return bytearray(v).decode('ascii')
cdef int min_max_tree_restructuring():
"""
>>> min_max_tree_restructuring()
"""
cdef char a[5]
a = [1, 2, 3, 4, 5]
cdef char[:] aview = a
return max(<char>1, aview[0])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment