Commit c98048e1

c98048e104bdMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

Merge pull request #92 from notorious94/istiad/fix/issue#85

fix(codegen): promote local sym_array type after empty-then-push (#85)

Details

Commit
c98048e104bd
Parent
6ee8a675b277
Merge parent
e8d797a945dc

spinel_codegen.rbmodifiedView file

@@ -11131,6 +11131,19 @@
1113111131 end
1113211132 ki = ki + 1
1113311133 end
11134+ elsif arg_type == "symbol"
11135+ # sym_array uses sp_IntArray storage, so int_array
11136+ # helpers stay required even after promotion.
11137+ @needs_int_array = 1
11138+ ki = 0
11139+ while ki < names.length
11140+ if names[ki] == arr_name
11141+ if types[ki] == "int_array"
11142+ types[ki] = "sym_array"
11143+ end
11144+ end
11145+ ki = ki + 1
11146+ end
1113411147 end
1113511148 end
1113611149 end
@@ -17584,8 +17597,11 @@
1758417597 end
1758517598 vref = fiber_var_ref(lname)
1758617599 vt = find_var_type(lname)
17587- # Empty array literal: create the correct array type
17588- if vt == "str_array" || vt == "float_array" || is_ptr_array_type(vt) == 1
17600+ # Empty array literal: create the correct array type. Returning
17601+ # early here also preserves the scope's already-promoted type
17602+ # (issue #58, #85) — the fall-through path below would clobber
17603+ # vt with infer_type([])'s "int_array" via set_var_type.
17604+ if vt == "str_array" || vt == "float_array" || vt == "sym_array" || is_ptr_array_type(vt) == 1
1758917605 expr_id = @nd_expression[nid]
1759017606 if expr_id >= 0 && @nd_type[expr_id] == "ArrayNode"
1759117607 elems = parse_id_list(@nd_elements[expr_id])
@@ -17598,6 +17614,11 @@
1759817614 @needs_float_array = 1
1759917615 @needs_gc = 1
1760017616 emit(" " + vref + " = sp_FloatArray_new();")
17617+ elsif vt == "sym_array"
17618+ # sym_array shares sp_IntArray storage.
17619+ @needs_int_array = 1
17620+ @needs_gc = 1
17621+ emit(" " + vref + " = sp_IntArray_new();")
1760117622 else
1760217623 @needs_ptr_array = 1
1760317624 @needs_gc = 1