Skip to content

Commit 4fe43a6

Browse files
michalmuskalameta-codesync[bot]
authored andcommitted
tests for flattening remote unions
Summary: See next diff Reviewed By: ilya-klyuchnikov Differential Revision: D85669552 fbshipit-source-id: 124c06127e88c1bded404e0303a4a97f5f7eaa14
1 parent c3c68c0 commit 4fe43a6

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

crates/elp/src/resources/test/eqwalizer_tests/check/lists_tests.pretty

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,60 @@ Because in the expression's type:
5454
because
5555
binary() is not compatible with atom()
5656

57-
2 ERRORS
57+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
58+
┌─ check/src/lists_tests.erl:22:18
59+
60+
22 │ unit_list1(X) -> [X].
61+
│ ^^^
62+
│ │
63+
│ [X].
64+
Expression has type: [union2()]
65+
Context expected type: ['a'] | ['b'] | ['c']
66+
67+
68+
Because in the expression's type:
69+
[
70+
Here the type is: union1() | 'c'
71+
Context expects type: 'a'
72+
No candidate of the expression's type matches the expected type.
73+
]
74+
75+
------------------------------ Detailed message ------------------------------
76+
77+
[union2()] is not compatible with ['a'] | ['b'] | ['c']
78+
because
79+
[union2()] is not compatible with ['a']
80+
because
81+
union2() is not compatible with 'a'
82+
because
83+
union1() | 'c' is not compatible with 'a'
84+
85+
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
86+
┌─ check/src/lists_tests.erl:28:18
87+
88+
28 │ unit_list3(X) -> [X].
89+
│ ^^^
90+
│ │
91+
│ [X].
92+
Expression has type: [union2()]
93+
Context expected type: [union1()] | ['c']
94+
95+
96+
Because in the expression's type:
97+
[
98+
Here the type is a union type with some valid candidates: union1()
99+
However the following candidate: 'c'
100+
Differs from the expected type: 'a' | 'b'
101+
]
102+
103+
------------------------------ Detailed message ------------------------------
104+
105+
[union2()] is not compatible with [union1()] | ['c']
106+
because
107+
[union2()] is not compatible with [union1()]
108+
because
109+
union2() is not compatible with union1()
110+
because
111+
union1() | 'c' is not compatible with union1()
112+
113+
4 ERRORS

test_projects/eqwalizer_tests/check/src/lists_tests.erl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ lists_union_neg(V1, V2) -> [V1, V2].
1414
-spec lists_union_2_neg
1515
(atom(), [atom()] | [binary()]) -> [atom()] | [binary()].
1616
lists_union_2_neg(V, L) -> [V | L].
17+
18+
-type union1() :: a | b.
19+
-type union2() :: union1() | c.
20+
21+
-spec unit_list1(union2()) -> [a] | [b] | [c].
22+
unit_list1(X) -> [X].
23+
24+
-spec unit_list2(union2()) -> [union2()].
25+
unit_list2(X) -> [X].
26+
27+
-spec unit_list3(union2()) -> [union1()] | [c].
28+
unit_list3(X) -> [X].

0 commit comments

Comments
 (0)