Skip to content

Fix String case functions inconsistency - #15630

Closed
AlexGx wants to merge 1 commit into
elixir-lang:mainfrom
AlexGx:ag-string_case_conststency-fix
Closed

Fix String case functions inconsistency#15630
AlexGx wants to merge 1 commit into
elixir-lang:mainfrom
AlexGx:ag-string_case_conststency-fix

Conversation

@AlexGx

@AlexGx AlexGx commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Make String.upcase/2, String.downcase/2, and String.capitalize/2
consistently reject invalid modes when an empty or a single grapheme is passed.

Before

iex> String.capitalize("a", :invalid)
"A"
# expected: **(FunctionClauseError) no function clause matching in String.capitalize/2  

iex> String.upcase("", :invalid)
""
# expected: ** (FunctionClauseError) no function clause matching in String.upcase/2 

iex> String.capitalize("aa", :invalid)
** (FunctionClauseError) no function clause matching in String.downcase/2
# expected more verbose: ** (FunctionClauseError) no function clause matching in String.capitalize/2

After

Unsupported modes consistently fail as expected by public boundary

Inspired by #15585

@josevalim

Copy link
Copy Markdown
Member

I really think those cases will be best caught by the type system. The float made sense because the confusion between 0 and 0.0 is more subtle but here the type system will do a fine job. Thanks!

@josevalim josevalim closed this Jul 17, 2026
@AlexGx
AlexGx deleted the ag-string_case_conststency-fix branch July 17, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants