Skip to content

Avoid applying map update callbacks to absent branches#15248

Open
gldubc wants to merge 3 commits intoelixir-lang:mainfrom
gldubc:apply-none
Open

Avoid applying map update callbacks to absent branches#15248
gldubc wants to merge 3 commits intoelixir-lang:mainfrom
gldubc:apply-none

Conversation

@gldubc
Copy link
Copy Markdown
Member

@gldubc gldubc commented Apr 8, 2026

Fixes #15208.

map_update with a function callback passes a fun_apply down into the map BDD so it can typecheck the callback against the current value.

The problem was that this also happened on branches where the domain key does not exist at all. On those branches, such as empty_map(), we were calling fun_apply with none().

That is not useful: the callback is supposed to be checked against values that may actually come from the map. Passing none() can manufacture bogus failures, and in this case it eventually led to the crash from #15208 with remote captures like &Helpers.transform/1.

The fix is to stop invoking the callback on absent-key branches for non-forced updates. If the key is missing, that branch should just behave like a failed update, instead of pretending the callback was applied to none().

I also added a regression at the descriptor layer that checks we do not call the callback with none() from absent branches.

@gldubc gldubc marked this pull request as ready for review April 8, 2026 23:32
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.

Type checker crash in unwrap_domain_tuple/2 with Map.update!/3, remote capture, and empty-map guard

1 participant