Skip to content

Commit 220c228

Browse files
committed
Do not emit type warning on generated nodes
Closes #13727.
1 parent 438e13d commit 220c228

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/elixir/lib/module/types/helpers.ex

+7-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ defmodule Module.Types.Helpers do
9191
Emits a warnings.
9292
"""
9393
def warn(module, warning, meta, stack, context) do
94-
{fun, arity} = stack.function
95-
location = {stack.file, meta, {stack.module, fun, arity}}
96-
%{context | warnings: [{module, warning, location} | context.warnings]}
94+
if Keyword.get(meta, :generated, false) do
95+
context
96+
else
97+
{fun, arity} = stack.function
98+
location = {stack.file, meta, {stack.module, fun, arity}}
99+
%{context | warnings: [{module, warning, location} | context.warnings]}
100+
end
97101
end
98102

99103
@doc """

lib/elixir/test/elixir/module/types/expr_test.exs

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ defmodule Module.Types.ExprTest do
66
import TypeHelper
77
import Module.Types.Descr
88

9+
defmacro generated(x) do
10+
quote generated: true do
11+
unquote(x).foo()
12+
end
13+
end
14+
915
test "literal" do
1016
assert typecheck!(true) == atom([true])
1117
assert typecheck!(false) == atom([false])
@@ -21,6 +27,10 @@ defmodule Module.Types.ExprTest do
2127
assert typecheck!(fn -> :ok end) == fun()
2228
end
2329

30+
test "generated" do
31+
assert typecheck!([x = 1], generated(x)) == dynamic()
32+
end
33+
2434
describe "funs" do
2535
test "incompatible" do
2636
assert typewarn!([%x{}], x.(1, 2)) ==

0 commit comments

Comments
 (0)