Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 16, 2024
1 parent df7860c commit e050d3a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lib/elixir/lib/module/types/descr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ defmodule Module.Types.Descr do
def term_type?(:term), do: true
def term_type?(descr), do: subtype_static(unfolded_term(), Map.delete(descr, :dynamic))

def dynamic_term_type?(descr), do: descr == %{dynamic: :term}

def gradual?(:term), do: false
def gradual?(descr), do: is_map_key(descr, :dynamic)

Expand Down
6 changes: 6 additions & 0 deletions lib/elixir/lib/module/types/of.ex
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ defmodule Module.Types.Of do

defp collect_var_traces(traces) do
traces
|> Enum.reject(fn {_expr, _file, type, _formatter} -> dynamic_term_type?(type) end)
|> case do
[] -> traces
filtered -> filtered
end
|> Enum.reverse()
|> Enum.map(fn {expr, file, type, formatter} ->
meta = get_meta(expr)
Expand All @@ -542,6 +547,7 @@ defmodule Module.Types.Of do
formatted_type: to_quoted_string(type)
}
end)
|> Enum.sort_by(&{&1.meta[:line], &1.meta[:column]})
end

def format_traces(traces) do
Expand Down
6 changes: 0 additions & 6 deletions lib/elixir/test/elixir/kernel/binary_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ defmodule Kernel.BinaryTest do
assert_compile_error(message, fn ->
Code.eval_string(~s[<<"foo"::float>>])
end)

message = "invalid literal ~c\"foo\""

assert_compile_error(message, fn ->
Code.eval_string(~s[<<'foo'::binary>>])
end)
end

@bitstring <<"foo", 16::4>>
Expand Down
10 changes: 0 additions & 10 deletions lib/elixir/test/elixir/kernel/expansion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2812,16 +2812,6 @@ defmodule Kernel.ExpansionTest do
end)
end

test "raises for invalid literals" do
assert_compile_error(~r"invalid literal :foo in <<>>", fn ->
expand(quote(do: <<:foo>>))
end)

assert_compile_error(~r"invalid literal \[\] in <<>>", fn ->
expand(quote(do: <<[]::size(8)>>))
end)
end

test "raises on binary fields with size in matches" do
assert expand(quote(do: <<x::binary-size(3), y::binary>> = "foobar"))

Expand Down
21 changes: 21 additions & 0 deletions lib/elixir/test/elixir/module/types/pattern_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ defmodule Module.Types.PatternTest do
test "refines information across patterns" do
assert typecheck!([%y{}, %x{}, x = y, x = Point], y) == dynamic(atom([Point]))
end

test "errors on conflicting refinements" do
assert typeerror!([a = b, a = :foo, b = :bar], {a, b}) ==
~l"""
the following pattern will never match:
a = b
where "a" was given the type:
# type: dynamic(:foo)
# from: types_test.ex:29
a = :foo
where "b" was given the type:
# type: dynamic(:bar)
# from: types_test.ex:29
b = :bar
"""
end
end

describe "structs" do
Expand Down

0 comments on commit e050d3a

Please sign in to comment.