Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

False positives on map literals with union/negation on variable keys

Aperta
#15,909 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
elixir, erlang
Ambito
compilers

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di elixir-lang/elixir

Tutte le issue di elixir-lang/elixir

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.