Skip to content

Commit 20f16f9

Browse files
committed
fix(workflow-code): flag a loop condition reading its own iteration by display name
The run resolves <W.index> to loop w by normalized name, so the self-reference check compares normalized names too.
1 parent a3cd487 commit 20f16f9

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎packages/workflow-code/src/compile/blocks.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
BLOCK_RETRY_MIN_TRIES,
1212
BLOCK_RETRY_MIN_WAIT_MS,
1313
type BlockRetryConfig,
14+
normalizeWorkflowBlockName,
1415
type WorkflowBranchKind,
1516
} from '@sim/workflow-types/workflow'
1617
import { encodeAnchor } from '../anchors'
@@ -1893,13 +1894,14 @@ function checkLoopCondition(
18931894
if (text.trim() === '') return
18941895
const at = rangeOf(ctx, property.value)
18951896
const selfReads = new Set<string>()
1897+
const ownName = normalizeWorkflowBlockName(decl.name)
18961898
const runnable = text.replace(REFERENCE_CANDIDATE, (match: string, inner: string) => {
18971899
if (!isLikelyWorkflowReferenceSegment(match)) return match
18981900
const segments = parseStoredPath(inner)
18991901
const [head, field] = segments ?? []
19001902
if (
19011903
head?.kind === 'name' &&
1902-
head.name === decl.key &&
1904+
normalizeWorkflowBlockName(head.name) === ownName &&
19031905
field?.kind === 'name' &&
19041906
LOOP_PROPERTIES.includes(field.name)
19051907
) {

‎packages/workflow-code/src/compile/checks.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,4 +909,10 @@ describe('loop conditions', () => {
909909
])
910910
expect(findings(whileLoop('<loop.index> < 3'), 'W_REF_OUT_OF_SCOPE')).toEqual([])
911911
})
912+
913+
it("warns on the loop's own iteration field read by its display name, which the run resolves to the loop", () => {
914+
expect(findings(whileLoop('<W.index> < 3'), 'W_REF_OUT_OF_SCOPE')).toEqual([
915+
expect.objectContaining({ blockKey: 'w' }),
916+
])
917+
})
912918
})

0 commit comments

Comments
 (0)