Commit 9f9082b5

9f9082b5133bMerged

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

Description

Merge pull request #299 from ryanseys/rs-fix-silent-fallback

fix: replace silent UnknownNode_* fallback with hard compile error

Details

Commit
9f9082b5133b
Parent
3f8973a7e8a5
Merge parent
7b2fd09e6224

spinel_codegen.rbmodifiedView file

@@ -662,6 +662,11 @@
662662 if field == "unescaped"
663663 @nd_unescaped[nid] = val
664664 end
665+ if field == "kind"
666+ # UnsupportedNode carries the Prism node-type name here so
667+ # codegen can surface a precise compile error.
668+ @nd_content[nid] = val
669+ end
665670 end
666671
667672 def set_int_field(nid, field, val)
@@ -680,6 +685,11 @@
680685 if field == "start_line"
681686 @nd_value[nid] = val
682687 end
688+ if field == "source_line"
689+ # UnsupportedNode carries the source line so codegen can cite
690+ # location in the compile error.
691+ @nd_value[nid] = val
692+ end
683693 end
684694
685695 def set_ref_field(nid, field, ref_id)
@@ -17791,6 +17801,13 @@
1779117801 return "0"
1779217802 end
1779317803 t = @nd_type[nid]
17804+ if t == "UnsupportedNode"
17805+ # The parser emitted this sentinel because it hit a Prism node
17806+ # type it doesn't know how to serialize. Refusing to compile is
17807+ # far better than the historical silent "0".
17808+ $stderr.puts "Spinel: cannot compile " + @nd_content[nid] + " at line " + @nd_value[nid].to_s + " (unsupported Ruby syntax)"
17809+ exit(1)
17810+ end
1779417811 if t == "IntegerNode"
1779517812 return @nd_value[nid].to_s
1779617813 end
@@ -25358,6 +25375,11 @@
2535825375 return
2535925376 end
2536025377 t = @nd_type[nid]
25378+ if t == "UnsupportedNode"
25379+ # Same loud-error path as compile_expr's UnsupportedNode arm.
25380+ $stderr.puts "Spinel: cannot compile " + @nd_content[nid] + " at line " + @nd_value[nid].to_s + " (unsupported Ruby syntax)"
25381+ exit(1)
25382+ end
2536125383 if t == "MultiWriteNode"
2536225384 compile_multi_write(nid)
2536325385 return