Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/isc/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export interface ExpandOptions {

/** Expand every `use` in the document's stages; rulesets themselves never execute. */
export function expandDocument(doc: IscDocument, opts: ExpandOptions = {}): IscDocument {
// WO18 G7 (py canon): a ruleset declared twice is a load error —
// keep-first silently hides map bugs and first-`.find` lookup makes
// the executed body declaration-order dependent.
const seenRs = new Set<string>()
for (const rs of doc.rulesets ?? []) {
if (!seenRs.has(rs.name)) seenRs.add(rs.name)
else throw new IscLoadError(`ruleset "${rs.name}" declared more than once in ${doc.systemCode}`)
}
const scope: ExpandScope = {
doc,
docKey: doc.systemCode,
Expand Down
8 changes: 8 additions & 0 deletions test/isc/wf1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ describe("expandDocument — cycle and resolution errors (§3.2, §6.4)", () =>
expect(() => expandDocument(doc)).toThrow(/use cycle/)
})

it("rejects a duplicate ruleset definition (py canon - keep-first hides map bugs)", () => {
const doc = parseIsc(
minimalWrap(`ruleset a { sub "x" "1" }\nruleset a { sub "x" "2" }\nstage main { use a }`),
)
expect(() => expandDocument(doc)).toThrow(IscLoadError)
expect(() => expandDocument(doc)).toThrow(/declared more than once/)
})

it("rejects a mutual cycle", () => {
const doc = parseIsc(
minimalWrap(`ruleset a { use b }\nruleset b { use a }\nstage main { use a }`),
Expand Down
Loading