Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
372836d623 | ||
|
|
444cd7e6bd | ||
|
|
cacb175ab3 | ||
|
|
bfce3ed7a9 | ||
|
|
06811cbdc8 | ||
|
|
7a6b35422c |
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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>}
|
||||
```
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user