@@ -203,7 +203,7 @@ defmodule Module.Types.Expr do
203
203
stack = push_expr_stack ( expr , stack )
204
204
205
205
with { :ok , _expr_type , context } <- of_expr ( case_expr , stack , context ) ,
206
- :ok <- of_clauses ( clauses , stack , context ) ,
206
+ { :ok , context } <- of_clauses ( clauses , stack , context ) ,
207
207
do: { :ok , :dynamic , context }
208
208
end
209
209
@@ -212,7 +212,7 @@ defmodule Module.Types.Expr do
212
212
stack = push_expr_stack ( expr , stack )
213
213
214
214
case of_clauses ( clauses , stack , context ) do
215
- :ok -> { :ok , :dynamic , context }
215
+ { :ok , context } -> { :ok , :dynamic , context }
216
216
{ :error , reason } -> { :error , reason }
217
217
end
218
218
end
@@ -224,23 +224,31 @@ defmodule Module.Types.Expr do
224
224
def of_expr ( { :try , _meta , [ blocks ] } = expr , stack , context ) do
225
225
stack = push_expr_stack ( expr , stack )
226
226
227
- result =
228
- each_ok ( blocks , fn
229
- { :rescue , clauses } ->
230
- each_ok ( clauses , fn
231
- { :-> , _ , [ [ { :in , _ , [ var , _exceptions ] } ] , body ] } ->
227
+ { result , context } =
228
+ reduce_ok ( blocks , context , fn
229
+ { :rescue , clauses } , context ->
230
+ reduce_ok ( clauses , context , fn
231
+ { :-> , _ , [ [ { :in , _ , [ var , _exceptions ] } ] , body ] } , context = acc ->
232
232
{ _type , context } = new_pattern_var ( var , context )
233
- of_expr_ok ( body , stack , context )
234
233
235
- { :-> , _ , [ [ var ] , body ] } ->
234
+ with { :ok , context } <- of_expr_context ( body , stack , context ) do
235
+ { :ok , keep_warnings ( acc , context ) }
236
+ end
237
+
238
+ { :-> , _ , [ [ var ] , body ] } , context = acc ->
236
239
{ _type , context } = new_pattern_var ( var , context )
237
- of_expr_ok ( body , stack , context )
240
+
241
+ with { :ok , context } <- of_expr_context ( body , stack , context ) do
242
+ { :ok , keep_warnings ( acc , context ) }
243
+ end
238
244
end )
239
245
240
- { block , body } when block in @ try_blocks ->
241
- of_expr_ok ( body , stack , context )
246
+ { block , body } , context = acc when block in @ try_blocks ->
247
+ with { :ok , context } <- of_expr_context ( body , stack , context ) do
248
+ { :ok , keep_warnings ( acc , context ) }
249
+ end
242
250
243
- { block , clauses } when block in @ try_clause_blocks ->
251
+ { block , clauses } , context when block in @ try_clause_blocks ->
244
252
of_clauses ( clauses , stack , context )
245
253
end )
246
254
@@ -254,18 +262,18 @@ defmodule Module.Types.Expr do
254
262
def of_expr ( { :receive , _meta , [ blocks ] } = expr , stack , context ) do
255
263
stack = push_expr_stack ( expr , stack )
256
264
257
- result =
258
- each_ok ( blocks , fn
259
- { :do , { :__block__ , _ , [ ] } } ->
260
- :ok
265
+ { result , context } =
266
+ reduce_ok ( blocks , context , fn
267
+ { :do , { :__block__ , _ , [ ] } } , context ->
268
+ { :ok , context }
261
269
262
- { :do , clauses } ->
270
+ { :do , clauses } , context ->
263
271
of_clauses ( clauses , stack , context )
264
272
265
- { :after , [ { :-> , _meta , [ head , body ] } ] } ->
273
+ { :after , [ { :-> , _meta , [ head , body ] } ] } , context = acc ->
266
274
with { :ok , _type , context } <- of_expr ( head , stack , context ) ,
267
- { :ok , _type , _context } <- of_expr ( body , stack , context ) ,
268
- do: :ok
275
+ { :ok , _type , context } <- of_expr ( body , stack , context ) ,
276
+ do: { :ok , keep_warnings ( acc , context ) }
269
277
end )
270
278
271
279
case result do
@@ -282,7 +290,7 @@ defmodule Module.Types.Expr do
282
290
with { :ok , context } <- reduce_ok ( clauses , context , & for_clause ( & 1 , stack , & 2 ) ) ,
283
291
{ :ok , context } <- reduce_ok ( opts , context , & for_option ( & 1 , stack , & 2 ) ) do
284
292
if opts [ :reduce ] do
285
- with :ok <- of_clauses ( block , stack , context ) do
293
+ with { :ok , context } <- of_clauses ( block , stack , context ) do
286
294
{ :ok , :dynamic , context }
287
295
end
288
296
else
@@ -437,22 +445,23 @@ defmodule Module.Types.Expr do
437
445
end
438
446
439
447
defp with_option ( { :else , clauses } , stack , context ) do
440
- case of_clauses ( clauses , stack , context ) do
441
- :ok -> { :ok , context }
442
- { :error , reason } -> { :error , reason }
443
- end
448
+ of_clauses ( clauses , stack , context )
444
449
end
445
450
446
451
defp of_clauses ( clauses , stack , context ) do
447
- each_ok ( clauses , fn { :-> , _meta , [ head , body ] } ->
452
+ reduce_ok ( clauses , context , fn { :-> , _meta , [ head , body ] } , context = acc ->
448
453
{ patterns , guards } = extract_head ( head )
449
454
450
455
with { :ok , _ , context } <- Pattern . of_head ( patterns , guards , stack , context ) ,
451
- { :ok , _expr_type , _context } <- of_expr ( body , stack , context ) ,
452
- do: :ok
456
+ { :ok , _expr_type , context } <- of_expr ( body , stack , context ) ,
457
+ do: { :ok , keep_warnings ( acc , context ) }
453
458
end )
454
459
end
455
460
461
+ defp keep_warnings ( context , % { warnings: warnings } ) do
462
+ % { context | warnings: warnings }
463
+ end
464
+
456
465
defp extract_head ( [ { :when , _meta , args } ] ) do
457
466
case Enum . split ( args , - 1 ) do
458
467
{ patterns , [ guards ] } -> { patterns , flatten_when ( guards ) }
@@ -479,13 +488,6 @@ defmodule Module.Types.Expr do
479
488
end
480
489
end
481
490
482
- defp of_expr_ok ( expr , stack , context ) do
483
- case of_expr ( expr , stack , context ) do
484
- { :ok , _type , _context } -> :ok
485
- { :error , reason } -> { :error , reason }
486
- end
487
- end
488
-
489
491
defp new_pattern_var ( { :_ , _meta , var_context } , context ) when is_atom ( var_context ) do
490
492
{ :dynamic , context }
491
493
end
0 commit comments