Skip to content

Keep exclusions local when printing list type unions - #15926

Open
claytongentry wants to merge 1 commit into
elixir-lang:mainfrom
claytongentry:preserve-list-union-exclusions
Open

claytongentry wants to merge 1 commit into
elixir-lang:mainfrom
claytongentry:preserve-list-union-exclusions

Conversation

@claytongentry

Copy link
Copy Markdown
Contributor

Assisted-by: Codex:GPT-6

add_to_list_normalize/4 can copy exclusions from an existing union alternative onto an incoming alternative that has no exclusions. This changes the meaning of the printed type. In the regression below, the input permits [:b], but every printed alternative excludes it.

When delete_elem/3 finds no matching exclusion, the current code recurses with the existing alternative’s n instead of the incoming alternative’s []. Insert {list, last, []} directly into the accumulator instead. Since n is necessarily nonempty in this clause, the previous recursive call immediately reached the catch-all clause. Direct insertion preserves that behavior while keeping each alternative’s exclusions separate.

The regression uses bare_intersection/2 to retain the structure that needs normalization during printing. It covers both leaking exclusions and incorrectly absorbing the incoming alternative into a later branch, which would lose [:d].

Insert incoming alternatives without copying exclusions from another branch.

Assisted-by: Codex:GPT-6
@josevalim

Copy link
Copy Markdown
Member

Is this a fix for #15837?

@claytongentry

Copy link
Copy Markdown
Contributor Author

It's not quite a fix for #15837; I was leaving that one for other maintainers. This is a separate, (so far as I can tell) unreported issue. I believe the cases from that issue still reproduce with this patch.

@josevalim
josevalim requested a review from gldubc September 22, 2026 16:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants