From 6aaed008a9eeab3159eec320c2f6f4503f6ea711 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Sat, 14 Nov 2026 11:45:34 +0800 Subject: [PATCH] fix(isc): a duplicate ruleset declaration is a load error (G7, py canon) ruby silently kept the FIRST definition; with in-block use the executed body was declaration-order dependent (audit probe tst-rscycle could pull content from BOTH definitions). The document builder now raises Interscript::MapLogicError "ruleset declared more than once in ", matching rs #19's builder check, ts #138's expandDocument check, and py's parse rejection. TDD: wf1 semantics spec red (loaded, kept first) -> green; rake 431/0/11. --- lib/interscript/isc/document_builder.rb | 10 +++++++++- spec/interscript/isc/wf1_semantics_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/interscript/isc/document_builder.rb b/lib/interscript/isc/document_builder.rb index 2b04b0ad..96eef081 100644 --- a/lib/interscript/isc/document_builder.rb +++ b/lib/interscript/isc/document_builder.rb @@ -52,7 +52,15 @@ def build languages_arr.concat(Array(item[:languages]).map { |l| ident(l) }) elsif item[:ruleset] # ISC-WF-1 W1: named ruleset declaration. - rulesets_arr << extract_ruleset(item) + rs = extract_ruleset(item) + # WO18 G7 (py canon): a duplicate declaration is a load + # error - keep-first hides map bugs and makes the executed + # body declaration-order dependent (rs #19, ts #138). + if rulesets_arr.any? { |existing| existing[:name] == rs[:name] } + raise Interscript::MapLogicError, + %(ruleset "#{rs[:name]}" declared more than once in #{@filename}) + end + rulesets_arr << rs elsif item[:stage] stages_arr << extract_stage(item) elsif item[:target] diff --git a/spec/interscript/isc/wf1_semantics_spec.rb b/spec/interscript/isc/wf1_semantics_spec.rb index 6c297181..eeb171b1 100644 --- a/spec/interscript/isc/wf1_semantics_spec.rb +++ b/spec/interscript/isc/wf1_semantics_spec.rb @@ -18,6 +18,16 @@ def interpreter_for(src) end describe "W1 expansion" do + # WO18 G7 (py canon): a duplicate ruleset declaration is a load + # error - keep-first hides map bugs and makes the executed body + # declaration-order dependent (rs #19, ts #138). + it "rejects a duplicate ruleset definition" do + src = 'system "T:g7:1" { ruleset a { sub "x" "1" } ruleset a { sub "x" "2" } stage main { use a } }' + expect { build_node_doc(src) }.to raise_error( + Interscript::MapLogicError, /ruleset "a" declared more than once/ + ) + end + let(:src) do <<~ISC system "T:e-L:Latn:1" {