Skip to content

Commit e060a45

Browse files
author
José Valim
committed
Do not always write tuple vars as tuple types, closes #6411
1 parent 9aeaa61 commit e060a45

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ defmodule Kernel.Typespec do
903903
end
904904

905905
# Handle tuples
906-
defp typespec({:tuple, meta, args}, _vars, _caller) when args == [] or is_atom(args) do
906+
defp typespec({:tuple, meta, []}, _vars, _caller) do
907907
{:type, line(meta), :tuple, :any}
908908
end
909909

lib/elixir/test/elixir/kernel/typespec_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,19 @@ defmodule Kernel.TypespecTest do
507507
specs(bytecode)
508508
end
509509

510+
test "@spec(spec) with tuples and tuple vars" do
511+
bytecode = test_module do
512+
def my_fun1(x), do: x
513+
def my_fun2(x), do: x
514+
@spec my_fun1(tuple) :: tuple
515+
@spec my_fun2(tuple) :: tuple when tuple: {integer, integer}
516+
end
517+
518+
assert [{{:my_fun1, 1}, [{:type, _, :fun, [{:type, _, :product, [{:type, _, :tuple, :any}]}, {:type, _, :tuple, :any}]}]},
519+
{{:my_fun2, 1}, [{:type, _, :bounded_fun, [{:type, _, :fun, [{:type, _, :product, [{:var, _, :tuple}]}, {:var, _, :tuple}]}, _]}]}] =
520+
specs(bytecode)
521+
end
522+
510523
test "@spec(spec) for unreachable private function" do
511524
# Run it inside capture_io/2 so that the "my_fun/1 is unused"
512525
# warning doesn't get printed among the ExUnit test results.

0 commit comments

Comments
 (0)