@@ -123,15 +123,17 @@ defmodule Module.Types.Pattern do
123123 pattern_vars = Map . to_list ( pattern_vars )
124124 changed = :lists . seq ( 0 , length ( types ) - 1 )
125125
126- case callback . ( types , changed , context ) do
127- { :ok , types , context } ->
128- of_pattern_recur ( types , pattern_vars , pattern_args , stack , context , callback )
126+ try do
127+ case callback . ( types , changed , context ) do
128+ { :ok , types , context } ->
129+ of_pattern_recur ( types , pattern_vars , pattern_args , stack , context , callback )
129130
130- { :error , context } ->
131- { types , context }
131+ { :error , context } ->
132+ { types , error_vars ( pattern_vars , context ) }
133+ end
134+ catch
135+ { types , context } -> { types , error_vars ( pattern_vars , context ) }
132136 end
133- catch
134- { types , context } -> { types , context }
135137 end
136138
137139 defp of_pattern_recur ( types , vars , args , stack , context , callback ) do
@@ -158,6 +160,7 @@ defmodule Module.Types.Pattern do
158160 end
159161
160162 :error ->
163+ # TODO: This should be precised about the operation (case/=/try/etc)
161164 context = Of . incompatible_error ( expr , expected , actual , stack , context )
162165 throw ( { types , context } )
163166 end
@@ -193,11 +196,17 @@ defmodule Module.Types.Pattern do
193196 # A simple structural comparison for optimization
194197 { :ok , ^ types , context } -> { types , context }
195198 { :ok , types , context } -> of_pattern_recur ( types , vars , args , stack , context , callback )
196- { :error , context } -> { types , context }
199+ { :error , context } -> { types , error_vars ( vars , context ) }
197200 end
198201 end
199202 end
200203
204+ defp error_vars ( vars , context ) do
205+ Enum . reduce ( vars , context , fn { _version , [ [ var | _path ] | _paths ] } , context ->
206+ Of . error_var ( var , context )
207+ end )
208+ end
209+
201210 defp of_pattern_intersect ( tree , expected , expr , stack , context ) do
202211 actual = of_pattern_tree ( tree , context )
203212 type = intersection ( actual , expected )
@@ -212,6 +221,7 @@ defmodule Module.Types.Pattern do
212221 { :error , error ( __MODULE__ , { :invalid_pattern , expr , context } , meta , stack , context ) }
213222
214223 true ->
224+ # TODO: This should be precised about the operation (case/=/try/etc)
215225 { :error , Of . incompatible_error ( expr , expected , actual , stack , context ) }
216226 end
217227 end
0 commit comments