Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#15,909 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
elixir, erlang
領域
compilers

調査の方向性

まず2つのElixirの例を再現し、issueで指定されているコンパイラパスを調べます: closed_map/5 と union_negated/4。変数キーのドメインと否定されたアトムキーが、どのように required または not_set() のエントリになるかを追跡し、その後、例が誤検知の警告なしに正しい型を生成することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Elixir
スター
26.7k
フォーク
3.7k
平均マージ
5時間 57分
マージ済み PR(30日)
55

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

elixir-lang/elixir のほかの issue

elixir-lang/elixir の issue をすべて見る

似ている issue

Elixir の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。