Skip to content
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

Disallow mixing of sequential and named sprintf parameters #12402

Merged

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Aug 19, 2022

Fixes the following for sprintf, IO#printf, and String#%:

  • Format strings cannot contain both sequential parameters (e.g. %s) and named parameters (e.g. %{foo}, %<bar>s). They are detected as soon as they consume an argument.
  • Calls that use named parameters in the format string must pass exactly a single Hash or NamedTuple, or a one-element Array or Tuple of it, depending on the overload chosen.
  • As a result of the refactoring, % is no longer one of the allowed field types; exactly %% must be used to print the percent sign, and other format modifiers are not allowed. This is the behavior in Ruby but not C. This is justified because format strings like %<a>% do not make any sense.

The PR also lays the groundwork for #12305.

@straight-shoota straight-shoota added this to the 1.6.0 milestone Sep 1, 2022
@straight-shoota straight-shoota merged commit a4c44b7 into crystal-lang:master Sep 5, 2022
@HertzDevil HertzDevil deleted the bug/sprintf-mixed-params branch September 6, 2022 01:46
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants