Skip to content

Commit 008126b

Browse files
committed
Improve docs and coverage
1 parent 292c38c commit 008126b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,10 @@ defmodule Kernel do
24632463
@doc """
24642464
Returns true if `term` is a struct of `name`; otherwise returns `false`.
24652465
2466+
`is_struct/2` does not check that `name` exists and is a valid struct.
2467+
If you want such validations, you must pattern match on the struct
2468+
instead, such as `match?(%URI{}, arg)`.
2469+
24662470
Allowed in guard tests.
24672471
24682472
## Examples

lib/elixir/test/elixir/kernel/lexical_tracker_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ defmodule Kernel.LexicalTrackerTest do
357357
assert URI in compile
358358
assert URI in exports
359359
refute URI in runtime
360+
361+
{{compile, exports, runtime, _}, _binding} =
362+
Code.eval_string("""
363+
defmodule Kernel.LexicalTrackerTest.StructPattern do
364+
def is_uri(%URI{}), do: true
365+
Kernel.LexicalTracker.references(__ENV__.lexical_tracker)
366+
end |> elem(3)
367+
""")
368+
369+
refute URI in compile
370+
assert URI in exports
371+
assert URI in runtime
360372
end
361373

362374
test "Macro.struct! adds an export dependency" do

0 commit comments

Comments
 (0)