Skip to content

Commit 44d94b0

Browse files
committed
Track tuples in the type system
1 parent fb6dd0f commit 44d94b0

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/elixir/lib/module/types/expr.ex

+7-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ defmodule Module.Types.Expr do
7373

7474
# {left, right}
7575
def of_expr({left, right}, stack, context) do
76-
of_expr({:{}, [], [left, right]}, stack, context)
76+
with {:ok, left, context} <- of_expr(left, stack, context),
77+
{:ok, right, context} <- of_expr(right, stack, context) do
78+
{:ok, tuple([left, right]), context}
79+
end
7780
end
7881

7982
# <<...>>>
@@ -112,11 +115,10 @@ defmodule Module.Types.Expr do
112115
{:ok, list(), context}
113116
end
114117

115-
# TODO: {...}
118+
# {...}
116119
def of_expr({:{}, _meta, exprs}, stack, context) do
117-
case map_reduce_ok(exprs, context, &of_expr(&1, stack, &2)) do
118-
{:ok, _types, context} -> {:ok, tuple(), context}
119-
{:error, context} -> {:error, context}
120+
with {:ok, types, context} <- map_reduce_ok(exprs, context, &of_expr(&1, stack, &2)) do
121+
{:ok, tuple(types), context}
120122
end
121123
end
122124

lib/elixir/test/elixir/module/types/expr_test.exs

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ defmodule Module.Types.ExprTest do
2121
assert typecheck!("foo") == binary()
2222
assert typecheck!([]) == empty_list()
2323
assert typecheck!([1, 2]) == non_empty_list()
24-
assert typecheck!({1, 2}) == tuple()
2524
assert typecheck!(%{}) == closed_map([])
2625
assert typecheck!(& &1) == fun()
2726
assert typecheck!(fn -> :ok end) == fun()
@@ -202,6 +201,12 @@ defmodule Module.Types.ExprTest do
202201
end
203202
end
204203

204+
describe "tuples" do
205+
test "creating tuples" do
206+
assert typecheck!({:ok, 123}) == tuple([atom([:ok]), integer()])
207+
end
208+
end
209+
205210
describe "maps/structs" do
206211
test "creating maps" do
207212
assert typecheck!(%{foo: :bar}) == closed_map(foo: atom([:bar]))

0 commit comments

Comments
 (0)