Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/elixir/lib/module/types/descr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5850,8 +5850,14 @@ defmodule Module.Types.Descr do

def tuple_insert_at(descr, index, type) when is_integer(index) and index >= 0 do
case :maps.take(:dynamic, unfold(type)) do
:error -> tuple_insert_at_checked(descr, index, type)
{dynamic, _static} -> dynamic(tuple_insert_at_checked(descr, index, dynamic))
:error ->
tuple_insert_at_checked(descr, index, type)

{dynamic_type, _static} ->
case tuple_insert_at_checked(descr, index, dynamic_type) do
atom when atom in [:badtuple, :badindex] -> atom
result -> dynamic(result)
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions lib/elixir/test/elixir/module/types/descr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,10 @@ defmodule Module.Types.DescrTest do
assert dynamic(union(tuple(), integer()))
|> tuple_insert_at(1, boolean())
|> equal?(dynamic(open_tuple([term(), boolean()])))

# Errors must propagate even when the inserted value is dynamic
assert tuple_insert_at(integer(), 0, dynamic()) == :badtuple
assert tuple_insert_at(tuple([atom([:ok])]), 2, dynamic()) == :badindex
end

test "tuple_values" do
Expand Down
Loading