hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

FormatString doesn't understand positional modifiers

Open HRMsimon opened this issue 11 years ago • 3 comments

<?hh // strict

function test(): void {
    printf('%1$d.%1$d', 1);
}
$ hh_client
test.php:4:5,26: Too many arguments (Typing[4105])
  /tmp/hh_server/hhi_3f2f7faf/printf.hhi:88:10,15: Definition is here
test.php:4:12,22: I don't understand the format string %1$ in %1$d.%1$d (Typing[4038])
  /tmp/hh_server/hhi_3f2f7faf/printf.hhi:70:35,46: You can add a new format specifier by adding format_0x24() to PlainSprintf
test.php:4:12,22: I don't understand the format string %1$ in %1$d.%1$d (Typing[4038])
  /tmp/hh_server/hhi_3f2f7faf/printf.hhi:70:35,46: You can add a new format specifier by adding format_0x24() to PlainSprintf

Not sure if this does just need the format_0x24() method or if Hack needs to know how to handle them (not sure if that part's missing)

HRMsimon avatar Aug 19 '15 23:08 HRMsimon

It's more involved - if you say "%s %d" the typechecker checks the next args are a string followed by an integer. It needs to be told it's the other way around for "%2$s %1$d"

fredemmott avatar Aug 20 '15 04:08 fredemmott

Additionally, FormatString can be used for things other than printf which might not recognize positional modifiers, eg AsyncMysqlClient::queryf()

fredemmott avatar Aug 20 '15 04:08 fredemmott

Duplicate of #2122

lexidor avatar Jul 01 '25 23:07 lexidor