False positives on map literals with union/negation on variable keys
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
調査の方向性
まず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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
elixir-lang/elixir のほかの issue
-
map_(get|put|update) ignore atom fields with static term() key対応中かも @lukaszsamson が 27 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
elixir-lang/elixir#15932 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
elixir-lang/elixir#15900 ·
メンテナーはふだん 1 日以内に返信
-
Gradual map domain with `none` looses static part when computing lower bound対応中かも @lukaszsamson が 45 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
elixir-lang/elixir#15854 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 56/100
elixir-lang/elixir#15837 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
elixir-lang/elixir#15829 ·
メンテナーはふだん 1 日以内に返信
elixir-lang/elixir の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
intellij-elixir/intellij-elixir#4501 ·
メンテナーはふだん 1 日以内に返信
-
Database text with `$` generates invalid `d2` output対応中かも @halostatue が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
bug(dashboard): gate card last-seen badge shows inventory-sync timestamp, not sweep observation timeオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
carverauto/serviceradar#5793 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
expert-lsp/expert#942 ·
メンテナーはふだん 1 日以内に返信
-
npm: file fetcher aborts with "engines.<key> must be a string" when package.json engines contains a nested object (e.g. cordovaDependencies)対応中かも @v-sachin-sandhu が 1 日前に担当しました。 オープンL: javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
dependabot/dependabot-core#16615 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信