Skip to content

Commit 41b9e1a

Browse files
michalmuskalameta-codesync[bot]
authored andcommitted
Clean up unions with none()
Summary: This is an eyesore when looking at type hints. We can get rid of them by a smart `apply` on `UnionType` that just removes `NoneType` - they're not meaningful. This also removes single-element unions - they were also causing some poor error messages with superfluous explanations stating same facts twice. There's no measurable change in time when running across the whole codebase. Reviewed By: TheGeorge, ilya-klyuchnikov Differential Revision: D85340363 fbshipit-source-id: 84759dcac6368c83624c7bd7f377273bb8151c37
1 parent dd36ea1 commit 41b9e1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+306
-512
lines changed

crates/elp/src/resources/test/eqwalizer_tests/check/case_predicates-OTP-26.pretty

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
6161
│ ^^^^^^
6262
│ │
6363
│ {'p', X}.
64-
Expression has type: {'p', none() | pid() | reference()}
64+
Expression has type: {'p', pid() | reference()}
6565
Context expected type: {'a', atom()} | {'p', pid()}
6666
6767

@@ -74,12 +74,12 @@ Because in the expression's type:
7474

7575
------------------------------ Detailed message ------------------------------
7676

77-
{'p', none() | pid() | reference()} is not compatible with {'a', atom()} | {'p', pid()}
77+
{'p', pid() | reference()} is not compatible with {'a', atom()} | {'p', pid()}
7878
because
7979
at tuple index 2:
80-
{'p', none() | pid() | reference()} is not compatible with {'p', pid()}
80+
{'p', pid() | reference()} is not compatible with {'p', pid()}
8181
because
82-
none() | pid() | reference() is not compatible with pid()
82+
pid() | reference() is not compatible with pid()
8383
because
8484
reference() is not compatible with pid()
8585

@@ -90,7 +90,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
9090
│ ^
9191
│ │
9292
│ X.
93-
Expression has type: 'undefined' | none() | 'restarting'
93+
Expression has type: 'undefined' | 'restarting'
9494
Context expected type: {'p', pid()} | 'undefined'
9595
9696

@@ -101,7 +101,7 @@ Because in the expression's type:
101101

102102
------------------------------ Detailed message ------------------------------
103103

104-
'undefined' | none() | 'restarting' is not compatible with {'p', pid()} | 'undefined'
104+
'undefined' | 'restarting' is not compatible with {'p', pid()} | 'undefined'
105105
because
106106
'restarting' is not compatible with {'p', pid()} | 'undefined'
107107
because
@@ -111,30 +111,16 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
111111
┌─ check/src/case_predicates.erl:174:16
112112
113113
174 │ lists:nth(1, L).
114-
│ ^
115-
│ │
116-
│ L.
117-
Expression has type: #{dynamic() => dynamic()} | none()
114+
│ ^ L.
115+
Expression has type: #{dynamic() => dynamic()}
118116
Context expected type: [T]
119-
120-
121-
Because in the expression's type:
122-
Here the type is: #{dynamic() => dynamic()}
123-
Context expects type: [T]
124117

125118
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
126119
┌─ check/src/case_predicates.erl:174:16
127120
128121
174 │ lists:nth(1, L).
129-
│ ^
130-
│ │
131-
│ L.
132-
Expression has type: #{dynamic() => dynamic()} | none()
122+
│ ^ L.
123+
Expression has type: #{dynamic() => dynamic()}
133124
Context expected type: [dynamic()]
134-
135-
136-
Because in the expression's type:
137-
Here the type is: #{dynamic() => dynamic()}
138-
Context expects type: [dynamic()]
139125

140126
11 ERRORS

crates/elp/src/resources/test/eqwalizer_tests/check/case_predicates-OTP-27.pretty

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
6161
│ ^^^^^^
6262
│ │
6363
│ {'p', X}.
64-
Expression has type: {'p', none() | pid() | reference()}
64+
Expression has type: {'p', pid() | reference()}
6565
Context expected type: {'a', atom()} | {'p', pid()}
6666
6767

@@ -74,12 +74,12 @@ Because in the expression's type:
7474

7575
------------------------------ Detailed message ------------------------------
7676

77-
{'p', none() | pid() | reference()} is not compatible with {'a', atom()} | {'p', pid()}
77+
{'p', pid() | reference()} is not compatible with {'a', atom()} | {'p', pid()}
7878
because
7979
at tuple index 2:
80-
{'p', none() | pid() | reference()} is not compatible with {'p', pid()}
80+
{'p', pid() | reference()} is not compatible with {'p', pid()}
8181
because
82-
none() | pid() | reference() is not compatible with pid()
82+
pid() | reference() is not compatible with pid()
8383
because
8484
reference() is not compatible with pid()
8585

@@ -90,7 +90,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
9090
│ ^
9191
│ │
9292
│ X.
93-
Expression has type: 'undefined' | none() | 'restarting'
93+
Expression has type: 'undefined' | 'restarting'
9494
Context expected type: {'p', pid()} | 'undefined'
9595
9696

@@ -101,7 +101,7 @@ Because in the expression's type:
101101

102102
------------------------------ Detailed message ------------------------------
103103

104-
'undefined' | none() | 'restarting' is not compatible with {'p', pid()} | 'undefined'
104+
'undefined' | 'restarting' is not compatible with {'p', pid()} | 'undefined'
105105
because
106106
'restarting' is not compatible with {'p', pid()} | 'undefined'
107107
because
@@ -111,30 +111,16 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
111111
┌─ check/src/case_predicates.erl:174:16
112112
113113
174 │ lists:nth(1, L).
114-
│ ^
115-
│ │
116-
│ L.
117-
Expression has type: #{dynamic() => dynamic()} | none()
114+
│ ^ L.
115+
Expression has type: #{dynamic() => dynamic()}
118116
Context expected type: [T]
119-
120-
121-
Because in the expression's type:
122-
Here the type is: #{dynamic() => dynamic()}
123-
Context expects type: [T]
124117

125118
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
126119
┌─ check/src/case_predicates.erl:174:16
127120
128121
174 │ lists:nth(1, L).
129-
│ ^
130-
│ │
131-
│ L.
132-
Expression has type: #{dynamic() => dynamic()} | none()
122+
│ ^ L.
123+
Expression has type: #{dynamic() => dynamic()}
133124
Context expected type: [dynamic()]
134-
135-
136-
Because in the expression's type:
137-
Here the type is: #{dynamic() => dynamic()}
138-
Context expects type: [dynamic()]
139125

140126
11 ERRORS

crates/elp/src/resources/test/eqwalizer_tests/check/case_predicates-OTP-28.pretty

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
6161
│ ^^^^^^
6262
│ │
6363
│ {'p', X}.
64-
Expression has type: {'p', none() | pid() | reference()}
64+
Expression has type: {'p', pid() | reference()}
6565
Context expected type: {'a', atom()} | {'p', pid()}
6666
6767

@@ -74,12 +74,12 @@ Because in the expression's type:
7474

7575
------------------------------ Detailed message ------------------------------
7676

77-
{'p', none() | pid() | reference()} is not compatible with {'a', atom()} | {'p', pid()}
77+
{'p', pid() | reference()} is not compatible with {'a', atom()} | {'p', pid()}
7878
because
7979
at tuple index 2:
80-
{'p', none() | pid() | reference()} is not compatible with {'p', pid()}
80+
{'p', pid() | reference()} is not compatible with {'p', pid()}
8181
because
82-
none() | pid() | reference() is not compatible with pid()
82+
pid() | reference() is not compatible with pid()
8383
because
8484
reference() is not compatible with pid()
8585

@@ -90,7 +90,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
9090
│ ^
9191
│ │
9292
│ X.
93-
Expression has type: 'undefined' | none() | 'restarting'
93+
Expression has type: 'undefined' | 'restarting'
9494
Context expected type: {'p', pid()} | 'undefined'
9595
9696

@@ -101,7 +101,7 @@ Because in the expression's type:
101101

102102
------------------------------ Detailed message ------------------------------
103103

104-
'undefined' | none() | 'restarting' is not compatible with {'p', pid()} | 'undefined'
104+
'undefined' | 'restarting' is not compatible with {'p', pid()} | 'undefined'
105105
because
106106
'restarting' is not compatible with {'p', pid()} | 'undefined'
107107
because
@@ -111,30 +111,16 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
111111
┌─ check/src/case_predicates.erl:174:16
112112
113113
174 │ lists:nth(1, L).
114-
│ ^
115-
│ │
116-
│ L.
117-
Expression has type: #{dynamic() => dynamic()} | none()
114+
│ ^ L.
115+
Expression has type: #{dynamic() => dynamic()}
118116
Context expected type: [T]
119-
120-
121-
Because in the expression's type:
122-
Here the type is: #{dynamic() => dynamic()}
123-
Context expects type: [T]
124117

125118
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
126119
┌─ check/src/case_predicates.erl:174:16
127120
128121
174 │ lists:nth(1, L).
129-
│ ^
130-
│ │
131-
│ L.
132-
Expression has type: #{dynamic() => dynamic()} | none()
122+
│ ^ L.
123+
Expression has type: #{dynamic() => dynamic()}
133124
Context expected type: [dynamic()]
134-
135-
136-
Because in the expression's type:
137-
Here the type is: #{dynamic() => dynamic()}
138-
Context expects type: [dynamic()]
139125

140126
11 ERRORS

crates/elp/src/resources/test/eqwalizer_tests/check/custom-OTP-26.pretty

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
30413041
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30423042
│ │
30433043
│ lists:partition(fun, L).
3044-
Expression has type: {[number()], [atom() | none()]}
3044+
Expression has type: {[number()], [atom()]}
30453045
Context expected type: {[atom()], [number()]}
30463046
30473047

@@ -3051,12 +3051,12 @@ Because in the expression's type:
30513051
Here the type is: number()
30523052
Context expects type: atom()
30533053
]
3054-
, [atom() | none()]}
3054+
, [atom()]}
30553055

30563056
------------------------------ Detailed message ------------------------------
30573057

30583058
at tuple index 1:
3059-
{[number()], [atom() | none()]} is not compatible with {[atom()], [number()]}
3059+
{[number()], [atom()]} is not compatible with {[atom()], [number()]}
30603060
because
30613061
[number()] is not compatible with [atom()]
30623062
because
@@ -3069,7 +3069,7 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
30693069
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30703070
│ │
30713071
│ lists:partition(fun, L).
3072-
Expression has type: {[{term(), number()}], [{term(), atom() | none()}]}
3072+
Expression has type: {[{term(), number()}], [{term(), atom()}]}
30733073
Context expected type: {[{term(), atom()}], [{term(), number()}]}
30743074
30753075

@@ -3081,12 +3081,12 @@ Because in the expression's type:
30813081
Context expects type: atom()
30823082
}
30833083
]
3084-
, [{term(), atom() | none()}]}
3084+
, [{term(), atom()}]}
30853085

30863086
------------------------------ Detailed message ------------------------------
30873087

30883088
at tuple index 1:
3089-
{[{term(), number()}], [{term(), atom() | none()}]} is not compatible with {[{term(), atom()}], [{term(), number()}]}
3089+
{[{term(), number()}], [{term(), atom()}]} is not compatible with {[{term(), atom()}], [{term(), number()}]}
30903090
because
30913091
[{term(), number()}] is not compatible with [{term(), atom()}]
30923092
because
@@ -3198,45 +3198,24 @@ error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types
31983198
┌─ check/src/custom.erl:2709:40
31993199
32003200
2709 │ (foo, A) -> binary_to_atom(A);
3201-
│ ^
3202-
│ │
3203-
│ A.
3201+
│ ^ A.
32043202
Expression has type: atom()
32053203
Context expected type: binary()
3206-
3207-
3208-
Because in the expression's type:
3209-
Here the type is: atom()
3210-
Context expects type: binary()
32113204

32123205
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
32133206
┌─ check/src/custom.erl:2710:40
32143207
32153208
2710 │ (bar, B) -> atom_to_binary(B);
3216-
│ ^
3217-
│ │
3218-
│ B.
3209+
│ ^ B.
32193210
Expression has type: binary()
32203211
Context expected type: atom()
3221-
3222-
3223-
Because in the expression's type:
3224-
Here the type is: binary()
3225-
Context expects type: atom()
32263212

32273213
error: incompatible_types (See https://fb.me/eqwalizer_errors#incompatible_types)
32283214
┌─ check/src/custom.erl:2711:50
32293215
32303216
2711 │ ({foo, bar}, I) -> binary_to_integer(I);
3231-
│ ^
3232-
│ │
3233-
│ I.
3217+
│ ^ I.
32343218
Expression has type: number()
32353219
Context expected type: binary()
3236-
3237-
3238-
Because in the expression's type:
3239-
Here the type is: number()
3240-
Context expects type: binary()
32413220

32423221
202 ERRORS

0 commit comments

Comments
 (0)