Skip to content

Widen ValidationError :key type to allow lists#151

Open
cgarvis wants to merge 1 commit into
dashbitco:mainfrom
cgarvis:fix/widen-validation-error-key-type
Open

Widen ValidationError :key type to allow lists#151
cgarvis wants to merge 1 commit into
dashbitco:mainfrom
cgarvis:fix/widen-validation-error-key-type

Conversation

@cgarvis
Copy link
Copy Markdown

@cgarvis cgarvis commented May 13, 2026

Summary

%NimbleOptions.ValidationError{}.key is typed atom() 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:

    keys ->
      error_tuple(
        keys,
        nil,
        "unknown options #{inspect(keys)}, valid options are: #{inspect(valid_opts)}"
      )
  • test "unknown options" asserts the list form:

    key: [:not_an_option1, :not_an_option2]
  • 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 where atom() is declared fires a warning. nimble_options is 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

-          key: atom(),
+          key: atom() | [atom()],

Plus a doc update on the :key field calling out the multi-key case.

Verification

mix test: 156/156 pass. mix compile clean under the new checker.

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>
@cgarvis cgarvis force-pushed the fix/widen-validation-error-key-type branch from 33d6226 to c6fba6b Compare May 13, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant