Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/elixir/lib/code/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ defmodule Code.Formatter do
defp tuple_to_algebra(meta, args, join, state) do
join = if eol?(meta, state), do: :line, else: join
fun = &quoted_to_algebra(&1, :parens_arg, &2)
args = flatten_last_keyword_arg(args)

{args_doc, join, state} =
args_to_algebra_with_comments(args, meta, false, :none, join, state, fun)
Expand Down Expand Up @@ -2474,6 +2475,17 @@ defmodule Code.Formatter do
defp keyword_key?(_),
do: false

# for {foo, bar: baz} tuples which are {foo, [bar: baz]}, returns [foo, bar: baz]
defp flatten_last_keyword_arg([last]) do
if keyword?(last), do: last, else: [last]
end

defp flatten_last_keyword_arg([]), do: []

defp flatten_last_keyword_arg([h | t]) do
[h | flatten_last_keyword_arg(t)]
end

defp eol?(_meta, %{skip_eol: true}), do: false
defp eol?(meta, _state), do: Keyword.get(meta, :newlines, 0) > 0

Expand Down
9 changes: 2 additions & 7 deletions lib/elixir/lib/enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4271,13 +4271,8 @@ defmodule Enum do

## Helpers

@compile {:inline,
entry_to_string: 1,
reduce: 3,
reduce_by: 3,
reduce_enumerable: 3,
reduce_range: 5,
map_range: 4}
@compile {:inline, entry_to_string: 1, reduce: 3, reduce_by: 3, reduce_enumerable: 3,
reduce_range: 5, map_range: 4}

defp entry_to_string(entry) when is_binary(entry), do: entry
defp entry_to_string(entry), do: String.Chars.to_string(entry)
Expand Down
13 changes: 2 additions & 11 deletions lib/elixir/lib/inspect/algebra.ex
Original file line number Diff line number Diff line change
Expand Up @@ -677,17 +677,8 @@ defmodule Inspect.Algebra do

# Algebra API

@compile {:inline,
empty: 0,
concat: 2,
break: 0,
break: 1,
glue: 2,
glue: 3,
flex_break: 0,
flex_break: 1,
flex_glue: 2,
flex_glue: 3}
@compile {:inline, empty: 0, concat: 2, break: 0, break: 1, glue: 2, glue: 3, flex_break: 0,
flex_break: 1, flex_glue: 2, flex_glue: 3}

@doc """
Returns a document entity used to represent nothingness.
Expand Down
5 changes: 1 addition & 4 deletions lib/elixir/lib/module/types/apply.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ defmodule Module.Types.Apply do
{:behaviour_info, callbacks: fas, optional_callbacks: fas},
{:module_info, module_info},
# TODO: Move this to a type signature declared by `defprotocol` (or perhaps part of the behaviour)
{:__protocol__,
module: atom(),
functions: fas,
consolidated?: boolean(),
{:__protocol__, module: atom(), functions: fas, consolidated?: boolean(),
impls: union(atom([:not_consolidated]), tuple([atom([:consolidated]), list(atom())]))}
]

Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/module/types/descr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ defmodule Module.Types.Descr do

defp term_or_optional(), do: @term_or_optional

@compile {:inline,
keep_optional: 1, remove_optional: 1, remove_optional_static: 1, optional_to_term: 1}
@compile {:inline, keep_optional: 1, remove_optional: 1, remove_optional_static: 1,
optional_to_term: 1}
defp keep_optional(descr) do
case descr do
%{dynamic: %{optional: 1}} -> %{dynamic: %{optional: 1}}
Expand Down
5 changes: 1 addition & 4 deletions lib/elixir/lib/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3200,10 +3200,7 @@ defmodule String do

## Helpers

@compile {:inline,
codepoint_byte_size: 1,
grapheme_byte_size: 1,
grapheme_to_binary: 1,
@compile {:inline, codepoint_byte_size: 1, grapheme_byte_size: 1, grapheme_to_binary: 1,
reverse_characters_to_binary: 1}

defp byte_size_unicode(binary) when is_binary(binary), do: byte_size(binary)
Expand Down
42 changes: 42 additions & 0 deletions lib/elixir/test/elixir/code_formatter/comments_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,48 @@ defmodule Code.Formatter.CommentsTest do
assert_format bad, good
end

test "with comments inside tuple keywords before and after" do
bad = ~S"""
{
:tuple,

# before 1
one: 1, # after 1

# before 2
two: 2, # after 2

# before 3
three: 3 # after 3

# final
}
"""

good = ~S"""

{
:tuple,

# before 1
# after 1
one: 1,

# before 2
# after 2
two: 2,

# before 3
# after 3
three: 3

# final
}
"""

assert_format bad, good
end

test "with comments inside bitstrings before and after" do
bad = ~S"""
<<
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/test/elixir/task/supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ defmodule Task.SupervisorTest do
children = [
{Task.Supervisor, strategy: :one_for_one, name: :simple_name},
{Task.Supervisor, strategy: :one_for_one, name: {:global, :global_name}},
{Task.Supervisor,
strategy: :one_for_one, name: {:via, Registry, {TaskSup.Registry, "via_name"}}}
{Task.Supervisor, strategy: :one_for_one,
name: {:via, Registry, {TaskSup.Registry, "via_name"}}}
]

assert {:ok, supsup} = Supervisor.start_link(children, strategy: :one_for_one)
Expand Down
3 changes: 2 additions & 1 deletion lib/mix/test/mix/rebar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ defmodule Mix.RebarTest do
deps: [
{
:rebar_override,
path: MixTest.Case.tmp_path("rebar_override"), app: false
path: MixTest.Case.tmp_path("rebar_override"),
app: false
}
]
]
Expand Down
40 changes: 11 additions & 29 deletions lib/mix/test/mix/release_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,7 @@ defmodule Mix.ReleaseTest do
"my_sample_mode/ebin/my_sample_mode.app",
{:application, :my_sample_mode,
applications: [:kernel, :stdlib, :elixir, :runtime_tools, :compiler],
description: ~c"my_sample_mode",
modules: [],
vsn: ~c"1.0.0"}
description: ~c"my_sample_mode", modules: [], vsn: ~c"1.0.0"}
)

apps = [my_sample_mode: :temporary]
Expand Down Expand Up @@ -799,11 +797,8 @@ defmodule Mix.ReleaseTest do
in_tmp(context.test, fn ->
write_app!(
"my_sample1/ebin/my_sample1.app",
{:application, :my_sample1,
applications: [:kernel, :stdlib, :elixir],
description: ~c"my_sample1",
modules: [],
vsn: ~c"1.0.0",
{:application, :my_sample1, applications: [:kernel, :stdlib, :elixir],
description: ~c"my_sample1", modules: [], vsn: ~c"1.0.0",
included_applications: [:runtime_tools]}
)

Expand All @@ -819,11 +814,8 @@ defmodule Mix.ReleaseTest do
in_tmp(context.test, fn ->
write_app!(
"my_sample2/ebin/my_sample2.app",
{:application, :my_sample2,
applications: [:kernel, :stdlib, :elixir, :runtime_tools],
description: ~c"my_sample",
modules: [],
vsn: ~c"1.0.0",
{:application, :my_sample2, applications: [:kernel, :stdlib, :elixir, :runtime_tools],
description: ~c"my_sample", modules: [], vsn: ~c"1.0.0",
included_applications: [:runtime_tools]}
)

Expand All @@ -839,11 +831,8 @@ defmodule Mix.ReleaseTest do
in_tmp(context.test, fn ->
write_app!(
"my_sample3/ebin/my_sample3.app",
{:application, :my_sample3,
applications: [:kernel, :stdlib, :elixir, :unknown],
optional_applications: [:unknown],
description: ~c"my_sample3",
modules: [],
{:application, :my_sample3, applications: [:kernel, :stdlib, :elixir, :unknown],
optional_applications: [:unknown], description: ~c"my_sample3", modules: [],
vsn: ~c"1.0.0"}
)

Expand All @@ -856,31 +845,24 @@ defmodule Mix.ReleaseTest do
in_tmp(context.test, fn ->
write_app!(
"has_optional/ebin/has_optional.app",
{:application, :has_optional,
applications: [:kernel, :stdlib, :elixir, :unknown],
optional_applications: [:unknown],
description: ~c"has_optional",
modules: [],
{:application, :has_optional, applications: [:kernel, :stdlib, :elixir, :unknown],
optional_applications: [:unknown], description: ~c"has_optional", modules: [],
vsn: ~c"1.0.0"}
)

write_app!(
"points_as_permanent/ebin/points_as_permanent.app",
{:application, :points_as_permanent,
applications: [:kernel, :stdlib, :elixir, :has_optional],
optional_applications: [:unknown],
description: ~c"points_as_permanent",
modules: [],
optional_applications: [:unknown], description: ~c"points_as_permanent", modules: [],
vsn: ~c"1.0.0"}
)

write_app!(
"points_as_temporary/ebin/points_as_temporary.app",
{:application, :points_as_temporary,
applications: [:kernel, :stdlib, :elixir, :has_optional],
optional_applications: [:unknown],
description: ~c"points_as_temporary",
modules: [],
optional_applications: [:unknown], description: ~c"points_as_temporary", modules: [],
vsn: ~c"1.0.0"}
)

Expand Down
Loading