@@ -105,31 +105,62 @@ defmodule Module.Types.Of do
105105 context
106106 end
107107
108- if gradual? ( old_type ) and type not in [ term ( ) , dynamic ( ) ] and not is_map_key ( data , :errored ) do
109- case compatible_intersection ( old_type , type ) do
110- { :error , _ } when allow_empty? ->
111- data = % {
112- data
113- | type: none ( ) ,
114- off_traces: new_trace ( expr , none ( ) , stack , off_traces )
115- }
116-
117- { none ( ) , % { context | vars: % { vars | version => data } } }
118-
119- { :ok , new_type } when new_type != old_type ->
120- data = % {
121- data
122- | type: new_type ,
123- off_traces: new_trace ( expr , new_type , stack , off_traces )
124- }
125-
126- { new_type , % { context | vars: % { vars | version => data } } }
127-
128- _ ->
129- { old_type , context }
108+ if match? ( % { pattern_info: % { allow_empty?: _ } } , context ) do
109+ if type not in [ term ( ) , dynamic ( ) ] and not is_map_key ( data , :errored ) do
110+ new_type = intersection ( old_type , type )
111+
112+ case empty? ( new_type ) do
113+ true when allow_empty? ->
114+ data = % {
115+ data
116+ | type: none ( ) ,
117+ off_traces: new_trace ( expr , none ( ) , stack , off_traces )
118+ }
119+
120+ { none ( ) , % { context | vars: % { vars | version => data } } }
121+
122+ false when new_type != old_type ->
123+ data = % {
124+ data
125+ | type: new_type ,
126+ off_traces: new_trace ( expr , new_type , stack , off_traces )
127+ }
128+
129+ { new_type , % { context | vars: % { vars | version => data } } }
130+
131+ _ ->
132+ { old_type , context }
133+ end
134+ else
135+ { old_type , context }
130136 end
131137 else
132- { old_type , context }
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 } } }
148+
149+ { :ok , new_type } when new_type != old_type ->
150+ data = % {
151+ data
152+ | type: new_type ,
153+ off_traces: new_trace ( expr , new_type , stack , off_traces )
154+ }
155+
156+ { new_type , % { context | vars: % { vars | version => data } } }
157+
158+ _ ->
159+ { old_type , context }
160+ end
161+ else
162+ { old_type , context }
163+ end
133164 end
134165 end
135166
0 commit comments