File tree Expand file tree Collapse file tree
packages/workflow-code/src/compile Expand file tree Collapse file tree Original file line number Diff line number Diff 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'
1617import { 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 ) {
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments