Repository navigation
Fix the compiler warnings, and the runtime bug hiding behind one - #5
Merged
dominicletz merged 2 commits intoNov 2, 2026
Merged
Conversation
The macro inlined a three-clause `case` at every call site, so a wrapped function with a narrower return type left a dead clause: Socket.TCP.accept!/1, accept!/2, Socket.Port.open!/1 and open!/2 all warned. A macro cannot know that return type; behind a function boundary every clause matches again.
`accept/2` answered `{:error, e.code}`, but Socket.Error defines only
:message, so the clause raises KeyError instead of returning a tuple:
`Socket.Web.accept(listener, timeout: 50)` dies on `key :code not found`.
`connect/3` already returns e.message.
`connect/3` also rescues Socket.TCP.Error and Socket.SSL.Error, defined
nowhere, so that clause can never match. Removed: those transports raise
Socket.Error, already caught above.
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.
Three small fixes, so that
mix compile --warnings-as-errors— which thisrepository's CI already runs — passes again on recent Elixir. One of them is a
crash, not just a warning.
Socket.Helpers.bang/1now does the:ok | {:ok, _} | {:error, _}unwrapping that
defbangused to inline at each call site. Behind a functionboundary, the compiler no longer flags dead clauses in
Socket.TCP.accept!/1,accept!/2,Socket.Port.open!/1andopen!/2.Socket.Web.accept/2returns{:error, e.message}on aSocket.Error,matching what
connect/3already did. It usede.code, a key that exceptiondoes not have, so
Socket.Web.accept(listener, timeout: 50)raisedKeyError. A new test covers it.Socket.Web.connect/3drops itsrescueonSocket.TCP.ErrorandSocket.SSL.Error. Neither module exists in this library, and thosetransports raise
Socket.Error, which the clause above already catches.No renaming, no reformatting, no other behaviour change.
Verified on Elixir 1.18.3 / OTP 26:
mix format --check-formatted,mix compile --warnings-as-errors,mix test(12 tests, 0 failures).