@@ -137,8 +137,6 @@ defmodule Module.Types.Expr do
137137 { @ stacktrace , context }
138138 end
139139
140- @ dynamic_or_term_list [ dynamic ( ) , term ( ) ]
141-
142140 # left = right
143141 def of_expr ( { := , _ , [ left_expr , right_expr ] } = match , expected , expr , stack , context ) do
144142 { left_expr , right_expr } = repack_match ( left_expr , right_expr )
@@ -151,19 +149,15 @@ defmodule Module.Types.Expr do
151149 _ ->
152150 type_fun =
153151 fn pattern_type , context ->
154- if expected in @ dynamic_or_term_list do
155- of_expr ( right_expr , pattern_type , expr , stack , context )
156- else
157- # See if we can use the expected type to further refine the pattern type,
158- # if we cannot, use the pattern type as that will fail later on.
159- { _ok_or_error , type } = compatible_intersection ( dynamic ( pattern_type ) , expected )
160- { result , context } = of_expr ( right_expr , type , expr , stack , context )
161-
162- # The function may still return a too broad type, so we refine once again
163- # to assign the most appropriate one for reverse arrows.
164- { _ok_or_error , result } = compatible_intersection ( result , expected )
165- { result , context }
166- end
152+ # See if we can use the expected type to further refine the pattern type,
153+ # if we cannot, use the pattern type as that will fail later on.
154+ { _ok_or_error , type } = compatible_intersection ( dynamic ( pattern_type ) , expected )
155+ { result , context } = of_expr ( right_expr , type , expr , stack , context )
156+
157+ # The function may still return a too broad type, so we refine once again
158+ # to assign the most appropriate one for reverse arrows.
159+ { _ok_or_error , result } = compatible_intersection ( result , expected )
160+ { result , context }
167161 end
168162
169163 Pattern . of_match ( left_expr , type_fun , match , stack , context )
@@ -335,7 +329,7 @@ defmodule Module.Types.Expr do
335329 version = Keyword . fetch! ( meta , :version )
336330
337331 { case_type , context } =
338- of_expr ( case_expr , @ pending , case_expr , % { stack | reverse_arrow: :cache } , base_context )
332+ of_expr ( case_expr , term ( ) , case_expr , % { stack | reverse_arrow: :cache } , base_context )
339333
340334 info = { :case , meta , case_expr , case_type }
341335
@@ -386,7 +380,7 @@ defmodule Module.Types.Expr do
386380 { patterns , _guards } = extract_head ( head )
387381 domain = Enum . map ( patterns , fn _ -> dynamic ( ) end )
388382
389- of_body = fn _args_types , body , context -> of_expr ( body , @ pending , body , stack , context ) end
383+ of_body = fn _args_types , body , context -> of_expr ( body , term ( ) , body , stack , context ) end
390384
391385 { acc , context } =
392386 of_clauses_fun ( clauses , domain , :fn , stack , context , of_body , [ ] , fn
@@ -483,6 +477,7 @@ defmodule Module.Types.Expr do
483477 of_clauses ( block , args , expected , :for_reduce , stack , context , reduce_type )
484478 else
485479 # TODO: Use the collectable protocol for the output
480+ # TODO: Use the expected type for the block output
486481 into = Keyword . get ( opts , :into , [ ] )
487482 { into_type , into_kind , context } = for_into ( into , meta , stack , context )
488483 { block_type , context } = of_expr ( block , @ pending , block , stack , context )
0 commit comments