@@ -1100,36 +1100,27 @@ function comparesDateTextAgainstUndeclared(
11001100 } ;
11011101 /** An element of the list `receiver` computes: `receiver[0]`. */
11021102 const elementOf = ( receiver : unknown ) : CelNode => ( { op : '[]' , args : [ receiver , { op : 'value' , args : 0n } ] } ) ;
1103- // [#38959 item 4] The whole source is walked, not stopped at the first
1104- // comparison that keeps the verdict: the one reported is the first ORDERING
1105- // (`<` `<=` `>` `>=`), then the first equality, so the operator, operands and
1106- // counterpart named are the comparison's own, never the Timestamp typing's
1107- // first fault elsewhere in the source (`'Due: ' + record.due_date == 'x' &&
1108- // record.due_date < record.title` names `<`, not `+`).
1109- let found = false ;
1110- let ordering : KeptDateTextComparison | undefined ;
1111- let equality : KeptDateTextComparison | undefined ;
1103+ // [#38959 item 4] The comparison that keeps the verdict is reported, so the
1104+ // operator, operands and counterpart named are its own, never the Timestamp
1105+ // typing's first fault elsewhere in the source (`'Due: ' + record.due_date
1106+ // == 'x' && record.due_date < record.title` names `<`, not `+`).
1107+ let kept : KeptDateTextComparison | null = null ;
11121108 /** A side's type as the Timestamp typing spells it: a date field's text is a Timestamp there. */
11131109 const spelled = ( t : string | undefined ) : string =>
11141110 t === DATE_TEXT_CEL_TYPE ? 'google.protobuf.Timestamp' : t ?? 'dyn' ;
1115- const keep = ( v : CelNode , kept : KeptDateTextComparison ) : void => {
1116- found = true ;
1117- if ( ORDERING_OPS . has ( v . op ) ) ordering ??= kept ;
1118- else equality ??= kept ;
1119- } ;
11201111 const visit = ( v : unknown , bound : ReadonlyMap < string , CelNode > ) : void => {
1121- if ( ordering ) return ;
1112+ if ( kept ) return ;
11221113 if ( Array . isArray ( v ) ) { for ( const child of v ) visit ( child , bound ) ; return ; }
11231114 if ( ! isCelNode ( v ) ) return ;
11241115 if ( DATE_TEXT_COMPARISON_OPS . has ( v . op ) && Array . isArray ( v . args ) && v . args . length === 2 ) {
11251116 // Without `macroElements` a macro variable proves nothing, as before #38959.
1126- if ( ! macroElements && bound . size > 0 && readsBound ( v . args , bound ) ) { keep ( v , { operator : v . op } ) ; return ; }
1117+ if ( ! macroElements && bound . size > 0 && readsBound ( v . args , bound ) ) { kept = { operator : v . op } ; return ; }
11271118 const [ sa , sb ] = ( v . args as unknown [ ] ) . map ( ( operand ) => substitute ( operand , bound ) ) ;
11281119 const [ a , b ] = [ sa . node , sb . node ] ;
11291120 const [ ta , tb ] = [ typeOf ( a ) , typeOf ( b ) ] ;
11301121 // A macro variable whose element does not check proves nothing: keep the verdict.
11311122 if ( ( sa . read && ta === undefined ) || ( sb . read && tb === undefined ) ) {
1132- keep ( v , { operator : v . op , operands : `${ spelled ( ta ) } ${ v . op } ${ spelled ( tb ) } ` } ) ;
1123+ kept = { operator : v . op , operands : `${ spelled ( ta ) } ${ v . op } ${ spelled ( tb ) } ` } ;
11331124 return ;
11341125 }
11351126 const dateFirst = ta === DATE_TEXT_CEL_TYPE && ! declared ( b , tb ) ;
@@ -1139,11 +1130,11 @@ function comparesDateTextAgainstUndeclared(
11391130 // computed text (`isoDate(today())`, `upper(…)`) or a macro's element
11401131 // is no reference to parse.
11411132 const read = otherType === 'string' ? typedFieldRef ( other , scope ) : null ;
1142- keep ( v , {
1133+ kept = {
11431134 operator : v . op ,
11441135 operands : `${ spelled ( ta ) } ${ v . op } ${ spelled ( tb ) } ` ,
11451136 ...( read ? { counterpart : read . written } : { } ) ,
1146- } ) ;
1137+ } ;
11471138 return ;
11481139 }
11491140 }
@@ -1159,7 +1150,7 @@ function comparesDateTextAgainstUndeclared(
11591150 visit ( v . args , bound ) ;
11601151 } ;
11611152 visit ( ast , new Map ( ) ) ;
1162- return found ? ordering ?? equality ?? { } : null ;
1153+ return kept ;
11631154}
11641155
11651156/**
0 commit comments