@@ -277,10 +277,19 @@ defmodule Module.Types.Expr do
277277 # for pat <- expr do expr end
278278 def of_expr ( { :for , _meta , args } = expr , stack , context ) do
279279 stack = push_expr_stack ( expr , stack )
280+ { clauses , [ [ { :do , block } | opts ] ] } = Enum . split ( args , - 1 )
280281
281- case reduce_ok ( args , context , & for_clause ( & 1 , stack , & 2 ) ) do
282- { :ok , _context } -> { :ok , :dynamic , context }
283- { :error , reason } -> { :error , reason }
282+ with { :ok , context } <- reduce_ok ( clauses , context , & for_clause ( & 1 , stack , & 2 ) ) ,
283+ { :ok , context } <- reduce_ok ( opts , context , & for_option ( & 1 , stack , & 2 ) ) do
284+ if opts [ :reduce ] do
285+ with :ok <- of_clauses ( block , stack , context ) do
286+ { :ok , :dynamic , context }
287+ end
288+ else
289+ with { :ok , _type , context } <- of_expr ( block , stack , context ) do
290+ { :ok , :dynamic , context }
291+ end
292+ end
284293 end
285294 end
286295
@@ -405,17 +414,6 @@ defmodule Module.Types.Expr do
405414 { :ok , context }
406415 end
407416
408- defp for_option ( { :do , [ { :-> , _ , [ pattern , body ] } ] } , stack , context ) do
409- case Pattern . of_pattern ( pattern , stack , context ) do
410- { :ok , _pattern_type , context } -> of_expr_context ( body , stack , context )
411- { :error , reason } -> { :error , reason }
412- end
413- end
414-
415- defp for_option ( { :do , body } , stack , context ) do
416- of_expr_context ( body , stack , context )
417- end
418-
419417 defp with_clause ( { :<- , _ , [ left , expr ] } , stack , context ) do
420418 { pattern , guards } = extract_head ( [ left ] )
421419
0 commit comments