Fix incorrect guard type refinement with length/map_size and != operator#15327
Merged
josevalim merged 2 commits intoelixir-lang:mainfrom Apr 30, 2026
Merged
Conversation
Previously `empty_list()` and `empty_map` were returned for `length(x) != n` and `map_size(x) != n` when n > 0. Now the types are widened to `list()` and `open_map()`
josevalim
reviewed
Apr 30, 2026
| assert typecheck!([x], not (0 != length(x)), x) == dynamic(empty_list()) | ||
|
|
||
| assert typecheck!([x], length(x) != 1, x) == dynamic(list(term())) | ||
| assert typecheck!([x], length(x) == 1, x) == dynamic(list(term())) |
Member
There was a problem hiding this comment.
This cannot be an empty list, right?
Member
|
This is a regression: they weren't tested explicitly previously, but things like These tests should succeed: |
Member
|
Yes, we need a few additional tests and cases! |
Contributor
Author
|
Tightened refinement to |
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.
Previously
empty_list()andempty_mapwere returned forlength(x) != nandmap_size(x) != nwhen n > 0. Now the types are widened tolist()andopen_map(). List/map of size exactly n when n > 0 cannot be expressed in the type system. The problem does not affect tuples as their sizes are encoded in typesFixes #15326