Repository navigation
Use a plain map for Ecto.Multi names to avoid Dialyzer opaqueness violations - #4800
Closed
roelandvanbatenburg wants to merge 1 commit into
Closed
roelandvanbatenburg wants to merge 1 commit into
roelandvanbatenburg wants to merge 1 commit into
Conversation
…lations
The names field defaulted to MapSet.new(), which the compiler inlines as a
%MapSet{map: %{}} literal. On Erlang/OTP 29 (and 28), Dialyzer infers the
opaque :sets.set/1 type for MapSet's internals from the :sets calls in
MapSet.put/2 and MapSet.member?/2, and reports call_without_opaque for any
caller passing Ecto.Multi.new() into another Ecto.Multi function. Elixir
documents @dialyzer :no_opaque as the workaround (elixir-lang/elixir#15674),
which every Ecto.Multi user would have to add.
Using a map keyed by operation name keeps the same semantics without the
opaque type.
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.
Summary
Ecto.Multi.new()still triggerscall_without_opaqueon Elixir 1.20.4 / Erlang/OTP 29.1, so #4707 isn't fully fixed by the Elixir 1.20MapSetchange. Elixir has since documented@dialyzer :no_opaqueas the workaround instead of fixing it further (elixir-lang/elixir#15673, #15674), which would mean everyEcto.Multicaller has to add it.The cause:
defstruct names: MapSet.new()is inlined as a%MapSet{map: %{}}literal. Dialyzer infers the opaque:sets.set/1forMapSetinternals from the:setscalls inMapSet.put/2/MapSet.member?/2, which flows into the success typing ofEcto.Multi.update/3and friends.This replaces the internal
MapSetwith a plain map (similar to #4708):Evidence
Minimal repro without Ecto, on Elixir 1.20.4 / OTP 29.1:
Downstream app calling
Ecto.Multi.new() |> Ecto.Multi.update(:user, changeset):lib/my_app/accounts.ex:236:23:call_without_opaque ... Call does not have expected term of type %Ecto.Multi{names: %MapSet{map: :sets.set(_)}, ...} (with opaque subterms)After:
Total errors: 0—done (passed successfully)mix teston Elixir 1.20.4 / OTP 29.1: 1609 passed (97 doctests, 1512 tests). Themulti.namesassertions intest/ecto/multi_test.exsare updated to the map shape.Merge Danger
Door: two-way
Blast Radius: small
namesis an internal field (@typep). Only code that readsmulti.namesdirectly and expects aMapSetwould notice; nothing in ecto_sql does.