Skip to content

Commit c8f7375

Browse files
committed
Support calling variables with union of function types
When a variable has a union of function types (e.g. fun((integer()) -> integer()) | fun((number()) -> atom())), calling it would fail because the type was wrapped in a singleton list and processed through expect_intersection_type, which rejects unions. Add a clause to expect_fun_type1 that unwraps single-element lists before processing, allowing the union to be handled by the existing fun_ty_union logic.
1 parent 4fb91d6 commit c8f7375

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

src/typechecker.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,11 @@ expect_fun_type1(_Env, {type, _, 'fun', [{type, _, any}, ResTy]}, Arity) ->
14991499
%% as we know Res2 is not {type, _, any}, which is explicitely matched on above.
15001500
ResTy = ?assert_type(ResTy, type()),
15011501
{fun_ty, ArgsTy, ResTy};
1502+
expect_fun_type1(Env, [Ty], Arity) when not is_list(Ty) ->
1503+
%% Single-element list: unwrap and process directly.
1504+
%% This handles cases like a variable with a union of function types
1505+
%% that gets wrapped in a list by type_check_fun/3.
1506+
expect_fun_type1(Env, Ty, Arity);
15021507
expect_fun_type1(Env, Tys, Arity) when is_list(Tys) ->
15031508
%% This is a spec, not really a type().
15041509
case expect_intersection_type(Env, Tys, Arity) of
File renamed without changes.

0 commit comments

Comments
 (0)