Skip to content

Commit c6ab1db

Browse files
authored
Fix opaqueness violation in Task.Supervisor (#14656)
1 parent 20cac29 commit c6ab1db

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

lib/elixir/lib/task.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,13 @@ defmodule Task do
14441444
end
14451445
end
14461446

1447+
# exported only to avoid dialyzer opaqueness check in internal Task modules
1448+
@doc false
1449+
@spec __alias__(pid()) :: Task.ref()
1450+
def __alias__(pid) do
1451+
build_alias(pid)
1452+
end
1453+
14471454
## Optimizations
14481455

14491456
defp build_monitor(pid) do

lib/elixir/lib/task/supervisor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ defmodule Task.Supervisor do
614614
case start_child_with_spec(supervisor, [get_owner(owner), :monitor], :temporary, shutdown) do
615615
{:ok, pid} ->
616616
if link_type == :link, do: Process.link(pid)
617-
alias = :erlang.monitor(:process, pid, alias: :demonitor)
617+
alias = Task.__alias__(pid)
618618
send(pid, {owner, alias, alias, get_callers(owner), {module, fun, args}})
619619
%Task{pid: pid, ref: alias, owner: owner, mfa: {module, fun, length(args)}}
620620

lib/elixir/test/elixir/fixtures/dialyzer/opaque_inline.ex

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
defmodule Dialyzer.Opaqueness do
2+
@spec bar(MapSet.t()) :: term()
3+
def bar(set) do
4+
set
5+
end
6+
7+
def foo() do
8+
# inlining of literals should not violate opaqueness check
9+
bar(MapSet.new([1, 2, 3]))
10+
end
11+
12+
# Task.Supervisor returns a Task.t() containing an opaque Task.ref()
13+
@spec run_task() :: Task.t()
14+
def run_task do
15+
Task.Supervisor.async(SupervisorName, fn -> :ok end)
16+
end
17+
end

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ defmodule Kernel.DialyzerTest do
5050
Module,
5151
Protocol,
5252
String,
53-
String.Chars
53+
String.Chars,
54+
Task,
55+
Task.Supervisor
5456
]
5557

5658
files = Enum.map(mods, &:code.which/1)
@@ -178,8 +180,8 @@ defmodule Kernel.DialyzerTest do
178180
assert_dialyze_no_warnings!(context)
179181
end
180182

181-
test "no warning on inlined calls returning opaque", context do
182-
copy_beam!(context, Dialyzer.OpaqueInline)
183+
test "no warning due to opaqueness edge cases", context do
184+
copy_beam!(context, Dialyzer.Opaqueness)
183185
assert_dialyze_no_warnings!(context)
184186
end
185187

0 commit comments

Comments
 (0)