Skip to content

Commit f889692

Browse files
committed
Ensure modules are loaded when verifying code
1 parent 606df6a commit f889692

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/phoenix_component/declarative.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ defmodule Phoenix.Component.Declarative do
10801080
@doc false
10811081
def __verify__(module, component_calls) do
10821082
for %{component: {submod, fun}} = call <- component_calls,
1083-
function_exported?(submod, :__components__, 0),
1083+
Code.ensure_loaded?(submod) and function_exported?(submod, :__components__, 0),
10841084
component = submod.__components__()[fun],
10851085
do: verify(module, call, component)
10861086

test/phoenix_component/verify_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ defmodule Phoenix.ComponentVerifyTest do
4242
assert warnings =~ "test/phoenix_component/verify_test.exs:#{line}: (file)"
4343
end
4444

45+
test "loads modules" do
46+
warnings =
47+
capture_io(:stderr, fn ->
48+
defmodule UnloadedAttrs do
49+
use Phoenix.Component
50+
51+
def render(assigns) do
52+
~H"""
53+
<Phoenix.LiveViewTest.Support.FunctionComponentWithAttrs.fun_attr_any unknown="foo" />
54+
"""
55+
end
56+
end
57+
end)
58+
59+
assert warnings =~
60+
"undefined attribute \"unknown\" for component Phoenix.LiveViewTest.Support.FunctionComponentWithAttrs"
61+
end
62+
4563
test "validate undefined attributes" do
4664
warnings =
4765
capture_io(:stderr, fn ->

0 commit comments

Comments
 (0)