Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Mixed type comprehension target narrows list elements to bitstrings

已关闭
#15,950 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #15952 来自 @josevalim —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
elixir
领域
compilers

调研方向

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

elixir-lang/elixir 的其他 Issue

查看 elixir-lang/elixir 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。