Repository navigation
Conversation
Since %_{} patterns became precise (#15635), is_struct/1, is_exception/1,
is_exception/2 and is_non_struct_map/1 emit "clause cannot match" and
"clause will never match" warnings when the type of the argument is
statically known, pointing at clauses that belong to the macro expansion.
Mark the whole expression expansion as generated, as is_struct/2 already
does.
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues were identified, and regression coverage is included.
Pull request overview
Marks type-check macro expansions as generated to suppress warnings from macro-internal clauses.
Changes:
- Updates
is_struct/1,is_non_struct_map/1, andis_exception. - Adds regression coverage for known types, maps, exceptions, and rescue clauses.
File summaries
| File | Description |
|---|---|
lib/elixir/test/elixir/module/types/integration_test.exs |
Adds compiler integration regression coverage. |
lib/elixir/test/elixir/module/types/expr_test.exs |
Tests warning suppression across type-check macros. |
lib/elixir/lib/kernel.ex |
Marks affected macro expansions as generated. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
Thank you. I'd say in this case it is correct to warn, it will always return true, but we need to improve the warning itself. Unless you can see cases where the warning is a false positive? What was the original case that led to this report? |
josevalim
reviewed
Sep 13, 2026
josevalim
reviewed
Sep 13, 2026
Co-authored-by: José Valim <[email protected]>
josevalim
reviewed
Sep 13, 2026
Member
|
After double checking, none of the other guards warn on this, they let the upper condition warn instead, so this is good to go. I just cleaned up the tests a bit! |
josevalim
reviewed
Sep 13, 2026
Member
|
💚 💙 💜 💛 ❤️ |
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.
Since
%_{}patterns became precise (#15635), the type-check macros leak warnings from their own expansion whenever the argument type is statically known. Callingis_struct/1on a struct:The
_ -> falseclause belongs to the macro expansion, so the warning points at code the caller never wrote. The same happens withis_exception/1andis_non_struct_map/1, and in rescue clauses (rescue x -> ... is_exception(x)); compiling the test suite on main emits this warning for the doctest oftry/rescue x -> ...in Kernel.SpecialForms. It also fires in the other direction:x = %{}; is_struct(x)warns that the%_{}clause will never match, ande = %ArgumentError{}; is_exception(e, ArgumentError)hitsis_exception/2through the pinned name.is_struct/2already wraps its whole expression expansion inquote generated: true, which is why it never triggers these warnings. This does the same for the remaining macros. Guards and match contexts are untouched.