Widen ValidationError :key type to allow lists#151
Open
cgarvis wants to merge 1 commit into
Open
Conversation
The struct already stores a list of atoms for the "unknown options" error (lib/nimble_options.ex:524 passes a list of keys; test "unknown options" asserts `key: [:not_an_option1, :not_an_option2]`). The @type for the field said `atom()` only, so the new set-theoretic checker in elixir-lang/elixir#15366 flags every caller of error_tuple at that site and cascades into every package that depends on nimble_options. Widening to `atom() | [atom()]` matches actual runtime behavior. Doc updated to call out the multi-key case. No code change, no test change. Signed-off-by: Chris Garvis <cgarvis@gmail.com>
33d6226 to
c6fba6b
Compare
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.
Summary
%NimbleOptions.ValidationError{}.keyis typedatom()but the struct already stores a list of atoms for the "unknown options" case. This PR widens the type to match runtime behavior.Evidence
The "unknown options" error path passes a list of keys at
lib/nimble_options.ex:524:test "unknown options"asserts the list form:Runtime behavior is intentional. The typespec was misleading.
Why this matters
The set-theoretic type checker introduced in elixir-lang/elixir#15366 reads
@type t :: %__MODULE__{key: atom()}literally. Every call site that passes a list whereatom()is declared fires a warning.nimble_optionsis depended on by several top Hex packages (finch, oban, req, swoosh, tesla, ex_aws, phoenix_live_view), so this single mismatch cascades into downstream warnings for their consumers.Widening the type matches what the code already does. No code change, no test change.
Change
Plus a doc update on the
:keyfield calling out the multi-key case.Verification
mix test: 156/156 pass.mix compileclean under the new checker.