Mixed type comprehension target narrows list elements to bitstrings
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #15952 来自 @josevalim —— 已关闭,未合并
评估
调研方向
Start with the for_into/5 implementation and the change introduced in commit 7427c0cf5, then reproduce the warning with the supplied mixed_into_repro.exs example. Trace how the mixed empty_list() and binary() target affects the inferred body type. Done means the example still returns {:found, "ok"} without the false-positive unreachable-clause warning, while invalid type narrowing remains reported.
由索引模型根据 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]
Elixir 1.21.0-dev (25fa668)
Operating system
any
Current behavior
When for comprehension into type contains both empty_list() and binary(), for_into/5 correctly returns both [:bitstring, :non_empty_list], but returns bitstring() as the expected type for the body
Repro:
save as mixed_into_repro.exs
defmodule MixedIntoRepro do
def run(flag) do
target = if flag, do: [], else: ""
value = if flag, do: :ok, else: "ok"
result = for _ <- [1], into: target, do: value
case result do
[head | _] ->
case head do
:ok -> :found
_ -> :other
end
text when is_binary(text) ->
text
end
end
end
IO.inspect({MixedIntoRepro.run(true), MixedIntoRepro.run(false)})
execute
elixir mixed_into_repro.exs
Result:
code works but prints a false positive warning
{:found, "ok"}
warning: the following clause will never match:
:ok ->
because it attempts to match on the result of:
head
which has type:
binary()
type warning found at:
│
10 │ :ok -> :found
│ ~~~~~~~~~~~~~
│
└─ mixed_into_repro.exs:10: MixedIntoRepro.run/1
Inroduced in 7427c0cf5
Expected behavior
No warning and invalid type narrowing
- 主要语言
- Elixir
- 星标
- 26.7k
- 派生
- 3.7k
- 平均合并
- 8 小时 8 分钟
- 30 天内合并 PR
- 61
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
elixir-lang/elixir 的其他 Issue
-
map_(get|put|update) ignore atom fields with static term() key可能已有人在做 @lukaszsamson 于 22 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
elixir-lang/elixir#15932 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
elixir-lang/elixir#15909 ·
维护者通常 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 于 39 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
elixir-lang/elixir#15854 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
elixir-lang/elixir#15837 ·
维护者通常 1 天内回复
查看 elixir-lang/elixir 的全部 Issue
相似的 Issue
-
ci-cd
难度 2/5 1-3 小时 新手友好度 72/100
carverauto/serviceradar#5648 ·
维护者通常 1 天内回复
-
Bug Elixir Waiting for: Product Owner
难度 2/5 1-3 小时 新手友好度 65/100
getsentry/sentry-elixir#1242 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
open-telemetry/opentelemetry-erlang-contrib#846 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4830 ·
维护者通常 1 天内回复