@@ -2188,6 +2188,8 @@ ExecResult assign_index_chain(Interpreter* interp, Env* env, Expr* idx_expr, Val
21882188 return make_error ("Out of memory" , stmt_line , stmt_col );
21892189 }
21902190
2191+ bool rhs_applied_directly = false;
2192+
21912193 walker = idx_expr ;
21922194 for (size_t i = 0 ; i < chain_len ; i ++ ) {
21932195 nodes [i ] = walker ;
@@ -2393,6 +2395,7 @@ ExecResult assign_index_chain(Interpreter* interp, Env* env, Expr* idx_expr, Val
23932395 free (starts ); free (ends ); free (orig_to_out );
23942396 // After slice assignment, set cur to base (no further chaining into this node)
23952397 cur = & base_val ;
2398+ rhs_applied_directly = true;
23962399 continue ;
23972400 }
23982401
@@ -2457,14 +2460,16 @@ ExecResult assign_index_chain(Interpreter* interp, Env* env, Expr* idx_expr, Val
24572460 }
24582461
24592462 // If we get here, the chain ended after resolving to a tensor element (e.g. a<1> = rhs)
2460- if (cur -> type != VAL_NULL && value_type_to_decl (cur -> type ) != value_type_to_decl (rhs .type )) {
2461- out = make_error ("Element type mismatch" , stmt_line , stmt_col );
2462- goto cleanup ;
2463+ if (!rhs_applied_directly ) {
2464+ if (cur -> type != VAL_NULL && value_type_to_decl (cur -> type ) != value_type_to_decl (rhs .type )) {
2465+ out = make_error ("Element type mismatch" , stmt_line , stmt_col );
2466+ goto cleanup ;
2467+ }
2468+ mtx_lock (& g_tns_lock );
2469+ value_free (* cur );
2470+ * cur = value_copy (rhs );
2471+ mtx_unlock (& g_tns_lock );
24632472 }
2464- mtx_lock (& g_tns_lock );
2465- value_free (* cur );
2466- * cur = value_copy (rhs );
2467- mtx_unlock (& g_tns_lock );
24682473
24692474 out = make_ok (value_null ());
24702475
0 commit comments