Mixed type comprehension target narrows list elements to bitstrings
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
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
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de elixir-lang/elixir
-
map_(get|put|update) ignore atom fields with static term() keyPosiblemente ocupada @lukaszsamson la tomó hace 20 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
elixir-lang/elixir#15932 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
elixir-lang/elixir#15909 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
elixir-lang/elixir#15900 ·
Los mantenedores suelen responder en 1 día
-
Gradual map domain with `none` looses static part when computing lower boundPosiblemente ocupada @lukaszsamson la tomó hace 38 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
elixir-lang/elixir#15854 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 56/100
elixir-lang/elixir#15837 ·
Los mantenedores suelen responder en 1 día
Todos los issues de elixir-lang/elixir
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
L: java:gradle L: java:maven L: ruby:bundler T: bug 🐞
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
dependabot/dependabot-core#16547 ·
Los mantenedores suelen responder en 1 día
-
github_actions
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
team-alembic/clarity#146 ·
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100