-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sprintf() with variables do not pass type checker #3725
Comments
The same could be said for the
|
I'm going to let the hack folks elaborate more on this when they have a chance. I imagine the reason we require literals (and have no plans to support anything else) for these parameters is so that the functions can be safely typed. Hack can't type-check the variadic arguments of While the compiler doesn't require this type of static knowledge (the code is valid as far as hhvm is concerned), the type checker can't statically analyze types if it doesn't have the information readily available. |
Yep, @paulbiss is exactly right. This is so we can statically check If you really want unchecked versions -- which I think is very ill-advised -- you can create your own partial mode wrappers or something similar. |
But correct me if I am wrong, you have the format string available, although it's through a variable. Couldn't you determine the type based on the variable? Or secondly, why wouldn't typing it to a string not provide what the checker needs? How would you accomplish i18n then? For scenarios where message strings would be passed to |
We could, but this goes down the road of dependent types, which we don't want to cross if we can avoid it. If it's really a constant string, then just write it inline!
We need to know what the actual value of the string is to parse it as a format string and know how many other parameters to
FB does i18n through another mechanism.
I disagree, but there's still nothing stopping you from writing an untyped wrapper, using |
D: Guess I'll figure something out. Thanks for the info! |
I receive the standard FormatString errors. I'm aware that this works:
sprintf('%s ago', '5 min');
But this does not.
$format = '%s ago'; sprintf($format, '5min');
Are there any plans to support this? I've tried forcing the type cast with
(string)
but no luck.This is the type error for reference.
The text was updated successfully, but these errors were encountered: