False positives on map literals with union/negation on variable keys
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
Direzione di ricerca
Inizia riproducendo i due esempi Elixir e ispeziona i percorsi del compilatore indicati nell’issue: closed_map/5 e union_negated/4. Traccia il modo in cui i domini delle chiavi variabili e le chiavi atomiche negate diventano voci required o not_set(), quindi verifica che gli esempi producano tipi corretti senza avvisi di falsi positivi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Existing issue
- I have searched existing issues and could not find a duplicate.
Elixir and Erlang/OTP versions
Erlang/OTP 28 [erts-16.4.0.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]
Interactive Elixir (1.21.0-dev)
Operating system
any
Current behavior
Map literal expressions with variable keys produce too small types that do not contain observed runtime values and result in false positive warnings.
Issue 1: Map literal whose key is :a or integer() records :a as required
Repro:
defmodule P22 do
def fin_dom(c) do
k = if c, do: :a, else: 5
m = %{k => 1}
case m do
%{a: _} -> :has_a
_ -> :no
end
end
end
Result:
warning: the following clause cannot match because the previous clauses already matched all possible values:
_ ->
it attempts to match on the result of:
m
which has the already matched type:
dynamic(%{integer() => integer(), a: integer()})
└─ iex:8: P22.fin_dom/1
Likely reason: closed_map/5 adds finite atoms as required keys even when domain_keys != []
Issue 2:
Map literals with a negated atom variable key mark the negated atom as not_set()
Repro:
defmodule P21 do
def neg_key(s1, s2) do
k1 = String.to_atom(s1)
k2 = case String.to_atom(s2) do :foo -> :not_foo; o -> o end
m = %{k1 => :baz, k2 => :baz2}
case m do
%{foo: _} -> :has_foo
_ -> :no
end
end
def neg2(s1, s2) do
k1 = case String.to_atom(s1) do :a -> :na; o -> o end
k2 = case String.to_atom(s2) do :b -> :nb; o -> o end
m = %{k1 => 1, k2 => 2}
case m do
%{b: _} -> :has_b
_ -> :no
end
end
end
Result:
warning: the following clause will never match:
%{foo: _} ->
because it attempts to match on the result of:
m
which has type:
dynamic(%{atom() => :baz or :baz2, foo: not_set()})
└─ iex:9: P21.neg_key/2
warning: the following clause will never match:
%{b: _} ->
because it attempts to match on the result of:
m
which has type:
dynamic(%{atom() => integer(), a: if_set(integer()), b: not_set()})
└─ iex:19: P21.neg2/2
IO.inspect({P21.neg_key("foo","bar"), P21.neg2("b","c")}) # {:has_foo, :has_b}
Note neg2 also shows the asymmetry: a is if_set (correct) but b is not_set (wrong)
Likely reason: closed_map/5 and union_negated/4 make every negated atom not_set() without consulting the :atom domain
Expected behavior
Proper types constructed, no warnings
- Lingua principale
- Elixir
- Stelle
- 26.7k
- Fork
- 3.7k
- Merge medio
- 8h 7m
- PR unite (30g)
- 60
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di elixir-lang/elixir
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
elixir-lang/elixir#15980 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
elixir-lang/elixir#15950 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
map_(get|put|update) ignore atom fields with static term() keyForse già presa @lukaszsamson l’ha presa 19 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
elixir-lang/elixir#15932 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 64/100
elixir-lang/elixir#15900 ·
I maintainer di solito rispondono entro 1 giorno
-
Gradual map domain with `none` looses static part when computing lower boundForse già presa @lukaszsamson l’ha presa 37 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
elixir-lang/elixir#15854 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di elixir-lang/elixir
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
ash-project/ash_ai#249 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
teslamate-org/teslamate#5856 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing v9
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
revelrylabs/harmonium#715 ·
I maintainer di solito rispondono entro 1 giorno
-
Feature:Resolution
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
intellij-elixir/intellij-elixir#4396 ·
I maintainer di solito rispondono entro 1 giorno