Skip to content

Commit ef56e81

Browse files
committed
Improve coverage over union calls
1 parent 1557d1d commit ef56e81

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ defmodule Module.Types.ExprTest do
148148

149149
assert typewarn!(try(do: :ok, after: URI.unknown("foo"))) ==
150150
{dynamic(), "URI.unknown/1 is undefined or private"}
151+
152+
# Check it also emits over a union
153+
assert typewarn!(
154+
[x = Atom, y = GenServer, z],
155+
(
156+
mod =
157+
cond do
158+
z -> x
159+
true -> y
160+
end
161+
162+
mod.to_string(:atom)
163+
)
164+
) ==
165+
{union(dynamic(), binary()), "GenServer.to_string/1 is undefined or private"}
151166
end
152167

153168
test "calling a nullary function on non atoms" do
@@ -180,6 +195,34 @@ defmodule Module.Types.ExprTest do
180195
# from: types_test.ex:LINE-1
181196
<<x::integer>>
182197
"""
198+
199+
assert typeerror!(
200+
[<<x::integer>>, y = Atom, z],
201+
(
202+
mod =
203+
cond do
204+
z -> x
205+
true -> y
206+
end
207+
208+
mod.to_string(:atom)
209+
)
210+
) ==
211+
~l"""
212+
expected a module (an atom) when invoking to_string/1 in expression:
213+
214+
mod.to_string(:atom)
215+
216+
where "mod" was given the type:
217+
218+
# type: dynamic(Atom or integer()) or integer()
219+
# from: types_test.ex:LINE-9
220+
mod =
221+
cond do
222+
z -> x
223+
true -> y
224+
end
225+
"""
183226
end
184227

185228
test "capture a function with non atoms" do

0 commit comments

Comments
 (0)