Skip to content

Commit 28f4fdc

Browse files
committed
Fix dialyzer warning in Code.format_string!/2 (#14928)
* Fix dialyzer warning in Code.format_string!/2 Tentative fix for #14927 * Add regression test for IO.inspect/2 opts
1 parent ee1dc07 commit 28f4fdc

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/elixir/lib/code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ defmodule Code do
10901090
@doc since: "1.6.0"
10911091
@spec format_string!(binary, [format_opt]) :: iodata
10921092
def format_string!(string, opts \\ []) when is_binary(string) and is_list(opts) do
1093-
line_length = Keyword.get(opts, :line_length, 98)
1093+
{line_length, opts} = Keyword.pop(opts, :line_length, 98)
10941094

10951095
to_quoted_opts =
10961096
[
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule Dialyzer.Regressions do
2+
def io_inspect_opts do
3+
IO.inspect(123, label: "foo", limit: :infinity)
4+
end
5+
6+
def format_opts do
7+
Code.format_string!("",
8+
line_length: 120,
9+
force_do_end_blocks: true,
10+
locals_without_parens: true,
11+
migrate: true
12+
)
13+
end
14+
end

lib/elixir/test/elixir/kernel/dialyzer_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ defmodule Kernel.DialyzerTest do
185185
assert_dialyze_no_warnings!(context)
186186
end
187187

188+
test "no warning in various non-regression cases", context do
189+
copy_beam!(context, Dialyzer.Regressions)
190+
assert_dialyze_no_warnings!(context)
191+
end
192+
188193
defp copy_beam!(context, module) do
189194
name = "#{module}.beam"
190195
File.cp!(Path.join(context.base_dir, name), Path.join(context.outdir, name))

0 commit comments

Comments
 (0)