Fix source field typespecs in HTTPError and TransportError#373
Open
cgarvis wants to merge 1 commit into
Open
Conversation
Mint.HTTPError.t() and Mint.TransportError.t() only declare the :reason field in their @type t() definitions, omitting other struct fields (e.g. :module in Mint.HTTPError). When the set-theoretic type checker resolves these as closed-map types, a value matched via a struct pattern carries extra fields that fall outside the declared type, producing a :badstructfield diagnostic. The :source field stores the original Mint exception so that Exception.message/1 can delegate to it. Exception.t() is the accurate type for that usage and resolves the incompatibility.
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.
The
sourcefield inFinch.HTTPErrorandFinch.TransportErrorwas typed asMint.HTTPError.t() | nilandMint.TransportError.t() | nilrespectively. The set-theoretic type checker surfaced by elixir-lang/elixir#15366 treats@type t()definitions as closed-map types. BecauseMint.HTTPError.t()only declares{reason: reason()}and omits the:modulefield present in the actual struct, a value matched with%Mint.HTTPError{reason: reason, module: module} = errorcarries a:modulefield that falls outside the declared type. This produces a:badstructfielddiagnostic for the:sourcefield at the construction site.The
:sourcefield holds the original Mint exception so thatException.message/1can delegate to it.Exception.t()is the accurate type for that usage: it is an open-map type that admits any exception struct, including bothMint.HTTPErrorandMint.TransportError.Before:
After:
mix test: 206 tests, 0 failures, 1 skipped.