Repository navigation
Fix protocol consolidation crash on beams from older Elixir versions - #15995
Merged
josevalim merged 2 commits intoOct 17, 2026
Merged
Conversation
Commit 558215b ("Dispatch consolidated protocols through literal external funs") changed the definitions generated by defprotocol to __select_impl__/1, __dispatch_impl__/4, and __select_struct__/1, and Protocol.consolidate/5 assumed they are always present. Consolidating a protocol beam compiled before that change raised a bare MatchError (no match of right hand side value: nil) whenever an existing _build was reused, since Mix manifests do not record the Elixir version and the version string stayed 1.21.0-dev. * Bump Mix.Compilers.Elixir's @manifest_vsn from 37 to 38 so builds compiled with previous versions are fully recompiled * Raise a proper ArgumentError with an actionable message in Protocol.consolidate/5 when the expected definitions are missing, instead of a bare MatchError Fixes elixir-lang#15994 Assisted-by: OpenCode:glm-5.3:cloud Signed-off-by: Jonathan Gnagy <jonathan@therubyist.org>
josevalim
requested changes
Oct 17, 2026
Co-authored-by: José Valim <jose.valim@gmail.com>
Contributor
Author
|
Thanks for the assist! Sorry if the extra tests were too much. |
Member
|
No sweat, all good! |
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.
Fixes #15994
Problem
Since 558215b ("Dispatch consolidated protocols through literal external funs", #15986),
defprotocolgenerates__select_impl__/1,__dispatch_impl__/4, and__select_struct__/1, andProtocol.consolidate/5assumed those definitions are always present. Consolidating a protocol beam compiled before that commit raised a bareMatchError(no match of right hand side value: nil) whenever an existing_buildwas reused:Because Mix manifests do not record the Elixir version and the version string stayed
1.21.0-dev, Mix considered such a_buildfresh and kept the old protocol beams. This affects both dev builds acrossmainand, without a manifest bump, users upgrading between released versions with a reused_build.Solution
Bump
Mix.Compilers.Elixir's@manifest_vsnfrom37to38, so builds compiled with versions prior to the new protocol representation are fully recompiledRaise a proper
ArgumentErrorwith an actionable message inProtocol.consolidate/5when the expected definitions are missing, instead of a bareMatchError:I considered returning a new
{:error, reason}tuple, butMix.Compilers.Protocol.consolidate_each/4only handles:okand:no_beam_infoclauses, so an unknown error reason would crash Mix with aMatchErrorthere anyway.Macro.inspect_atom/2is used for the module name since theInspectprotocol cannot be relied on during consolidation.Tests
The new test in
lib/elixir/test/elixir/protocol/consolidation_test.exsbuilds a protocol beam that mimics the pre-1.21 layout (persisted__protocol__attribute and__protocol__/1, without the new internal definitions). It fails withMatchErrorbefore this change and passes after.Verified locally (OTP 29.0.5): full
make test_stdlib(7574 tests) andmake test_mix(948 tests) pass, plus an end-to-end smoke test recompiling a Mix project with a stale_buildfrom another Elixir version: recompilation happens cleanly, protocols consolidate, and both concrete andAny-fallback dispatch work.This contribution was written with the assistance of AI tooling and reviewed in full by the human submitter, who certifies the Developer Certificate of Origin via the
Signed-off-bytrailer on the commit.Assisted-by: OpenCode:glm-5.3:cloud