@@ -86,13 +86,14 @@ defmodule Module.Types.Of do
8686 or if we are doing a guard analysis or occurrence typing.
8787 Returns `true` if there was a refinement, `false` otherwise.
8888 """
89- def refine_body_var ( var_or_version , type , expr , stack , context , allow_empty? \\ false )
89+ @ skip_refinement_for [ term ( ) , dynamic ( ) ]
90+ def refine_body_var ( var_or_version , type , expr , stack , context )
9091
91- def refine_body_var ( { _ , meta , _ } , type , expr , stack , context , allow_empty? ) do
92- refine_body_var ( Keyword . fetch! ( meta , :version ) , type , expr , stack , context , allow_empty? )
92+ def refine_body_var ( { _ , meta , _ } , type , expr , stack , context ) do
93+ refine_body_var ( Keyword . fetch! ( meta , :version ) , type , expr , stack , context )
9394 end
9495
95- def refine_body_var ( version , type , expr , stack , context , allow_empty? )
96+ def refine_body_var ( version , type , expr , stack , context )
9697 when is_integer ( version ) or is_reference ( version ) do
9798 % { vars: % { ^ version => % { type: old_type , off_traces: off_traces } = data } = vars } = context
9899
@@ -105,12 +106,15 @@ defmodule Module.Types.Of do
105106 context
106107 end
107108
108- if match? ( % { pattern_info: % { allow_empty?: _ } } , context ) do
109- if type not in [ term ( ) , dynamic ( ) ] and not is_map_key ( data , :errored ) do
109+ case context do
110+ _ when type in @ skip_refinement_for or is_map_key ( data , :errored ) ->
111+ { old_type , context }
112+
113+ % { pattern_info: % { guard_context: guard_context } } ->
110114 new_type = intersection ( old_type , type )
111115
112116 case empty? ( new_type ) do
113- true when allow_empty? ->
117+ true when guard_context == :orelse ->
114118 data = % {
115119 data
116120 | type: none ( ) ,
@@ -131,21 +135,9 @@ defmodule Module.Types.Of do
131135 _ ->
132136 { old_type , context }
133137 end
134- else
135- { old_type , context }
136- end
137- else
138- if gradual? ( old_type ) and type not in [ term ( ) , dynamic ( ) ] and not is_map_key ( data , :errored ) do
139- case compatible_intersection ( old_type , type ) do
140- { :error , _ } when allow_empty? ->
141- data = % {
142- data
143- | type: none ( ) ,
144- off_traces: new_trace ( expr , none ( ) , stack , off_traces )
145- }
146-
147- { none ( ) , % { context | vars: % { vars | version => data } } }
148138
139+ _ ->
140+ case gradual? ( old_type ) and compatible_intersection ( old_type , type ) do
149141 { :ok , new_type } when new_type != old_type ->
150142 data = % {
151143 data
@@ -158,9 +150,6 @@ defmodule Module.Types.Of do
158150 _ ->
159151 { old_type , context }
160152 end
161- else
162- { old_type , context }
163- end
164153 end
165154 end
166155
0 commit comments