Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Mixed type comprehension target narrows list elements to bitstrings

Cerrado
#15,950 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #15952 de @josevalim — cerrado sin fusionar

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
elixir
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Elixir
Estrellas
26.7k
Forks
3.7k
Merge medio
8 h 8 min
PR fusionados (30 d)
61

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de elixir-lang/elixir

Todos los issues de elixir-lang/elixir

Issues similares

Más issues de Elixir

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.