Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Mixed type comprehension target narrows list elements to bitstrings

Aperta
#15,950 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
elixir
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Elixir
Stelle
26.7k
Fork
3.7k
Merge medio
8h 7m
PR unite (30g)
60

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di elixir-lang/elixir

Tutte le issue di elixir-lang/elixir

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.