fix: remove protocol definition default args deprecated in Elixir 1.20#792
Open
rafaels88 wants to merge 1 commit into
Open
fix: remove protocol definition default args deprecated in Elixir 1.20#792rafaels88 wants to merge 1 commit into
rafaels88 wants to merge 1 commit into
Conversation
Default arguments in defprotocol definitions are deprecated in Elixir 1.20 and will become a hard error in a future release. - Remove `\ :microsecond` defaults from Timex.Comparable.compare/3 and diff/3 - Remove `\ :utc` default from Timex.Protocol.to_datetime/2 - Drop now-invalid 1-arity @SPEC for to_datetime - Change defdelegate compare/2 and diff/2 in Timex to explicit calls with hardcoded :microsecond default to preserve public API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Default arguments in defprotocol definitions are deprecated in Elixir 1.20 and will become a hard error in a future release.
\ :microseconddefaults from Timex.Comparable.compare/3 and diff/3\ :utcdefault from Timex.Protocol.to_datetime/2@specforto_datetimedefdelegate compare/2anddiff/2in Timex to explicit calls with hardcoded:microseconddefault to preserve public APIThe warnings:
Summary of changes
Elixir 1.20 deprecated default arguments inside defprotocol definitions — they produce both f/n and f/n-1 as protocol variants, which will become a hard compile error in a future version. Timex 3.7.13 has three such defaults: compare/3, diff/3 in Timex.Comparable, and to_datetime/2 in Timex.Protocol.
Projects running --warnings-as-errors (a common CI setup) can't compile against this on Elixir 1.20.
This removes the three defaults from the protocol definitions and makes the 2-arity public wrappers in Timex supply the hardcoded defaults explicitly, so callers see no behaviour change.
Checklist