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

Mixed type comprehension target narrows list elements to bitstrings

クローズ
#15,950 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

  • #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分
マージ済み PR(30日)
61

環境構築

はじめの一歩

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

elixir-lang/elixir のほかの issue

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

似ている issue

Elixir の issue をもっと見る

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

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