@@ -175,14 +175,17 @@ class FormattingCall extends Call {
175175 )
176176 }
177177
178- /** Gets the `i`th argument to be formatted. */
178+ /** Gets the `i`th argument to be formatted. The index `i` is one-based. */
179179 Expr getArgumentToBeFormatted ( int i ) {
180- i >= 0 and
180+ i >= 1 and
181181 if this .hasExplicitVarargsArray ( )
182182 then
183183 result =
184- this .getArgument ( 1 + this .getFormatStringIndex ( ) ) .( ArrayCreationExpr ) .getInit ( ) .getInit ( i )
185- else result = this .getArgument ( this .getFormatStringIndex ( ) + 1 + i )
184+ this .getArgument ( 1 + this .getFormatStringIndex ( ) )
185+ .( ArrayCreationExpr )
186+ .getInit ( )
187+ .getInit ( i - 1 )
188+ else result = this .getArgument ( this .getFormatStringIndex ( ) + i )
186189 }
187190
188191 /** Holds if the varargs argument is given as an explicit array. */
@@ -441,14 +444,21 @@ private class PrintfFormatString extends FormatString {
441444 not result = fmtSpecRefersToSpecificIndex ( _)
442445 }
443446
447+ private int getFmtSpecRank ( int specOffset ) {
448+ rank [ result ] ( int i | this .fmtSpecIsRef ( i ) ) = specOffset
449+ }
450+
444451 override int getAnArgUsageOffset ( int argNo ) {
445452 argNo = fmtSpecRefersToSpecificIndex ( result )
446453 or
447454 fmtSpecRefersToSequentialIndex ( result ) and
448- argNo = count ( int i | i < result and fmtSpecRefersToSequentialIndex ( i ) )
455+ result = rank [ argNo ] ( int i | fmtSpecRefersToSequentialIndex ( i ) )
449456 or
450457 fmtSpecRefersToPrevious ( result ) and
451- argNo = count ( int i | i < result and fmtSpecRefersToSequentialIndex ( i ) ) - 1
458+ exists ( int previousOffset |
459+ getFmtSpecRank ( previousOffset ) = getFmtSpecRank ( result ) - 1 and
460+ previousOffset = getAnArgUsageOffset ( argNo )
461+ )
452462 }
453463}
454464
0 commit comments