Commit 3c017b41

3c017b411294Merged

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

Description

feat: error on global variable type mismatch

Emit a compile error when the same global variable is assigned different types (e.g. $x = 42 then $x = "hello").

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

Details

Commit
3c017b411294
Parent
ffdcb606e990

spinel_codegen.rbmodifiedView file

@@ -5407,6 +5407,18 @@
54075407 if not_in(gname, @gvar_names) == 1
54085408 @gvar_names.push(gname)
54095409 @gvar_types.push(gt)
5410+ else
5411+ # Check type consistency
5412+ gi = 0
5413+ while gi < @gvar_names.length
5414+ if @gvar_names[gi] == gname
5415+ if @gvar_types[gi] != gt && gt != "int" && gt != "nil"
5416+ $stderr.puts "Error: global variable " + gname + " type mismatch: " + @gvar_types[gi] + " vs " + gt
5417+ exit(1)
5418+ end
5419+ end
5420+ gi = gi + 1
5421+ end
54105422 end
54115423 end
54125424 end