@@ -133,24 +133,42 @@ def lower_Assign(self, state: lowering.State, node: ast.Assign) -> lowering.Resu
133133 stmt .result .name = lhs_name
134134 current_frame .defs [lhs_name ] = current_frame .push (stmt ).result
135135 case _:
136- for target , value in zip ( node .targets , result . data ) :
137- self .assign_item (state , target , value )
136+ for target in node .targets :
137+ self .assign_item (state , target , result )
138138
139139 def lower_AnnAssign (
140140 self , state : lowering .State , node : ast .AnnAssign
141141 ) -> lowering .Result :
142142 type_hint = self .get_hint (state , node .annotation )
143143 value = state .lower (node .value ).expect_one ()
144144 stmt = state .current_frame .push (TypeAssert (got = value , expected = type_hint ))
145- self .assign_item (state , node .target , stmt .result )
145+ self .assign_item_value (state , node .target , stmt .result )
146146
147147 def lower_AugAssign (
148148 self , state : lowering .State , node : ast .AugAssign
149149 ) -> lowering .Result :
150- self .assign_item (state , node .target , state .lower (node .value ).expect_one ())
150+ match node .target :
151+ case ast .Name (name , ast .Store ()):
152+ rhs = ast .Name (name , ast .Load ())
153+ case ast .Attribute (obj , attr , ast .Store ()):
154+ rhs = ast .Attribute (obj , attr , ast .Load ())
155+ case ast .Subscript (obj , slice , ast .Store ()):
156+ rhs = ast .Subscript (obj , slice , ast .Load ())
157+ self .assign_item_value (
158+ state ,
159+ node .target ,
160+ state .lower (ast .BinOp (rhs , node .op , node .value )).expect_one (),
161+ )
151162
152- @staticmethod
153- def assign_item (state : lowering .State , target , value : ir .SSAValue ):
163+ def lower_NamedExpr (
164+ self , state : lowering .State , node : ast .NamedExpr
165+ ) -> lowering .Result :
166+ value = state .lower (node .value ).expect_one ()
167+ self .assign_item_value (state , node .target , value )
168+ return value
169+
170+ @classmethod
171+ def assign_item_value (cls , state : lowering .State , target , value : ir .SSAValue ):
154172 current_frame = state .current_frame
155173 match target :
156174 case ast .Name (name , ast .Store ()):
@@ -168,9 +186,15 @@ def assign_item(state: lowering.State, target, value: ir.SSAValue):
168186 case _:
169187 raise lowering .BuildError (f"unsupported target { target } " )
170188
171- @staticmethod
172- def assert_assign_value_type (value : ir .SSAValue , type_hint : types .TypeAttribute ):
173- value_type = value .type .meet (type_hint )
174- if value_type is value_type .bottom ():
175- raise lowering .BuildError (f"Cannot assign { value .type } to { type_hint } " )
176- return value_type
189+ @classmethod
190+ def assign_item (cls , state : lowering .State , target , result : lowering .State .Result ):
191+ match target :
192+ case ast .Tuple (elts , ast .Store ()):
193+ if len (elts ) != len (result .data ):
194+ raise lowering .BuildError (
195+ f"tuple assignment length mismatch: { len (elts )} != { len (result .data )} "
196+ )
197+ for target , value in zip (elts , result .data ):
198+ cls .assign_item_value (state , target , value )
199+ case _:
200+ cls .assign_item_value (state , target , result .expect_one ())
0 commit comments