Commit edc12fed

edc12fed179cMerged

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

Description

fix: infer ForNode loop variable type from collection element type

for-in loop variables now correctly infer their type from the collection: str_array → string, float_array → float, ptr_array → element type. Previously always defaulted to int regardless of the collection type.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
edc12fed179c
Parent
ae3afb5c9a33

spinel_codegen.rbmodifiedView file

@@ -9066,8 +9066,21 @@
90669066 lname = @nd_name[tgt]
90679067 if not_in(lname, names) == 1
90689068 if not_in(lname, params) == 1
9069+ # Infer element type from collection
9070+ elem_type = "int"
9071+ coll = @nd_collection[nid]
9072+ if coll >= 0
9073+ ct = infer_type(coll)
9074+ if ct == "str_array"
9075+ elem_type = "string"
9076+ elsif ct == "float_array"
9077+ elem_type = "float"
9078+ elsif is_ptr_array_type(ct) == 1
9079+ elem_type = ptr_array_elem_type(ct)
9080+ end
9081+ end
90699082 names.push(lname)
9070- types.push("int")
9083+ types.push(elem_type)
90719084 end
90729085 end
90739086 end