Compare commits

...
6 Commits
Author SHA1 Message Date
jamauro 372836d623 Change variable from bk to bucket (#13921)
Simple change from `bk` to `bucket` for consistency with the rest of the doc
2024-10-21 18:00:21 +02:00
Jean Klingler 444cd7e6bd Fix crash in Macro.to_string/1 on invalid sigils (#13905) 2024-10-17 15:39:57 +09:00
Jean Klingler cacb175ab3 Add @doc false to Inspect.Algebra.no_limit/1 (#13893) 2024-10-10 18:21:49 +09:00
Jean Klingler bfce3ed7a9 Fix another dialyzer Kernel.with edge case (#13869)
Close https://github.com/elixir-lang/elixir/issues/13868
2024-09-30 20:11:05 +02:00
Vasily Suvorov 06811cbdc8 Fix typedoc for init_option (#13870)
Change `c:init/1` to`init/2` in the `typedoc`'s text
2024-09-30 15:41:35 +02:00
Igor Goryachev 7a6b35422c Fix logger translator tests under Erlang 27.1 (#13839) 2024-09-21 13:36:09 +02:00
9 changed files with 68 additions and 20 deletions
+10 -9
View File
@@ -174,16 +174,17 @@ defmodule Code.Normalizer do
# Sigils
defp do_normalize({sigil, meta, [{:<<>>, _, args} = string, modifiers]} = quoted, state)
when is_list(args) and is_atom(sigil) do
case Atom.to_string(sigil) do
"sigil_" <> _ ->
meta =
meta
|> patch_meta_line(state.parent_meta)
|> Keyword.put_new(:delimiter, "\"")
{sigil, meta, [do_normalize(string, %{state | parent_meta: meta}), modifiers]}
when is_atom(sigil) and is_list(args) and is_list(modifiers) do
with "sigil_" <> _ <- Atom.to_string(sigil),
true <- binary_interpolated?(args),
true <- List.ascii_printable?(modifiers) do
meta =
meta
|> patch_meta_line(state.parent_meta)
|> Keyword.put_new(:delimiter, "\"")
{sigil, meta, [do_normalize(string, %{state | parent_meta: meta}), modifiers]}
else
_ ->
normalize_call(quoted, state)
end
+15
View File
@@ -588,6 +588,21 @@ defmodule Inspect.Algebra do
doc_cons(doc1, doc2)
end
@doc ~S"""
Disable any rendering limit while rendering the given document.
## Examples
iex> doc = Inspect.Algebra.glue("hello", "world") |> Inspect.Algebra.group()
iex> Inspect.Algebra.format(doc, 10)
["hello", "\n", "world"]
iex> doc = Inspect.Algebra.no_limit(doc)
iex> Inspect.Algebra.format(doc, 10)
["hello", " ", "world"]
"""
@doc since: "1.14.0"
@spec no_limit(t) :: t
def no_limit(doc) do
doc_limit(doc, :infinity)
end
+1 -1
View File
@@ -595,7 +595,7 @@ defmodule Supervisor do
@typedoc "The supervisor reference."
@type supervisor :: pid | name | {atom, node}
@typedoc "Options given to `start_link/2` and `c:init/1`."
@typedoc "Options given to `start_link/2` and `init/2`."
@type init_option ::
{:strategy, strategy}
| {:max_restarts, non_neg_integer}
+1 -1
View File
@@ -124,7 +124,7 @@ iex> {:ok, registry} = GenServer.start_link(KV.Registry, :ok)
{:ok, #PID<0.136.0>}
iex> GenServer.cast(registry, {:create, "shopping"})
:ok
iex> {:ok, bk} = GenServer.call(registry, {:lookup, "shopping"})
iex> {:ok, bucket} = GenServer.call(registry, {:lookup, "shopping"})
{:ok, #PID<0.174.0>}
```
+1 -1
View File
@@ -426,7 +426,7 @@ translate_with_else(Meta, [{'else', Else}], S) ->
Clauses = elixir_erl_clauses:get_clauses('else', [{'else', Else ++ [RaiseClause]}], match),
{TranslatedClauses, SC} = elixir_erl_clauses:clauses(Clauses, SV#elixir_erl{extra=pin_guard}),
with_else_closure(Meta, TranslatedClauses, SC#elixir_erl{extra=SV#elixir_erl.extra}).
with_else_closure(Generated, TranslatedClauses, SC#elixir_erl{extra=SV#elixir_erl.extra}).
with_else_closure(Meta, TranslatedClauses, S) ->
Ann = ?ann(Meta),
@@ -172,6 +172,20 @@ defmodule Code.Normalizer.QuotedASTTest do
) == ~s[~S"""\n"123"\n"""]
end
test "regression: invalid sigil calls" do
assert quoted_to_string(quote do: sigil_r(<<"foo", 123>>, [])) ==
"sigil_r(<<\"foo\", 123>>, [])"
assert quoted_to_string(quote do: sigil_r(<<"foo">>, :invalid_modifiers)) ==
"sigil_r(\"foo\", :invalid_modifiers)"
assert quoted_to_string(quote do: sigil_r(<<"foo">>, [:invalid_modifier])) ==
"sigil_r(\"foo\", [:invalid_modifier])"
assert quoted_to_string(quote do: sigil_r(<<"foo">>, [])) == "~r\"foo\""
assert quoted_to_string(quote do: sigil_r(<<"foo">>, [?a, ?b, ?c])) == "~r\"foo\"abc"
end
test "tuple" do
assert quoted_to_string(quote do: {1, 2}) == "{1, 2}"
assert quoted_to_string(quote do: {1}) == "{1}"
@@ -0,0 +1,12 @@
defmodule Dialyzer.WithThrowingElse do
def with_throwing_else(map) do
with {:ok, foo} <- Map.fetch(map, :foo),
false <- Enum.empty?(foo) do
foo
else
# several clauses but one is a no_return
:error -> throw(:empty_map)
true -> nil
end
end
end
@@ -26,6 +26,7 @@ defmodule Kernel.DialyzerTest do
:elixir,
:elixir_env,
:elixir_erl_pass,
:maps,
ArgumentError,
Atom,
Code,
@@ -164,6 +165,11 @@ defmodule Kernel.DialyzerTest do
assert_dialyze_no_warnings!(context)
end
test "no warnings on with when multiple else clauses and one is a no_return", context do
copy_beam!(context, Dialyzer.WithThrowingElse)
assert_dialyze_no_warnings!(context)
end
test "no warnings on defmacrop", context do
copy_beam!(context, Dialyzer.Defmacrop)
assert_dialyze_no_warnings!(context)
+8 -8
View File
@@ -948,13 +948,13 @@ defmodule Logger.TranslatorTest do
test "translates Supervisor progress" do
{:ok, pid} = Supervisor.start_link([], strategy: :one_for_one)
assert capture_log(:info, fn ->
assert capture_log(:debug, fn ->
ref = Process.monitor(pid)
Supervisor.start_child(pid, worker(Task, [__MODULE__, :sleep, [self()]]))
Process.exit(pid, :normal)
receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
end) =~ ~r"""
\[info\] Child Task of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) started
\[(debug|info)\] Child Task of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) started
Pid: #PID<\d+\.\d+\.\d+>
Start Call: Task.start_link\(Logger.TranslatorTest, :sleep, \[#PID<\d+\.\d+\.\d+>\]\)
"""
@@ -963,36 +963,36 @@ defmodule Logger.TranslatorTest do
test "translates Supervisor progress with name" do
{:ok, pid} = Supervisor.start_link([], strategy: :one_for_one, name: __MODULE__)
assert capture_log(:info, fn ->
assert capture_log(:debug, fn ->
ref = Process.monitor(pid)
Supervisor.start_child(pid, worker(Task, [__MODULE__, :sleep, [self()]]))
Process.exit(pid, :normal)
receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
end) =~ ~r"""
\[info\] Child Task of Supervisor Logger.TranslatorTest started
\[(debug|info)\] Child Task of Supervisor Logger.TranslatorTest started
"""
{:ok, pid} = Supervisor.start_link([], strategy: :one_for_one, name: {:global, __MODULE__})
assert capture_log(:info, fn ->
assert capture_log(:debug, fn ->
ref = Process.monitor(pid)
Supervisor.start_child(pid, worker(Task, [__MODULE__, :sleep, [self()]]))
Process.exit(pid, :normal)
receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
end) =~ ~r"""
\[info\] Child Task of Supervisor Logger.TranslatorTest started
\[(debug|info)\] Child Task of Supervisor Logger.TranslatorTest started
"""
{:ok, pid} =
Supervisor.start_link([], strategy: :one_for_one, name: {:via, :global, __MODULE__})
assert capture_log(:info, fn ->
assert capture_log(:debug, fn ->
ref = Process.monitor(pid)
Supervisor.start_child(pid, worker(Task, [__MODULE__, :sleep, [self()]]))
Process.exit(pid, :normal)
receive do: ({:DOWN, ^ref, _, _, _} -> :ok)
end) =~ ~r"""
\[info\] Child Task of Supervisor Logger.TranslatorTest started
\[(debug|info)\] Child Task of Supervisor Logger.TranslatorTest started
"""
end