@@ -366,6 +366,15 @@ defmodule Module.Types.Pattern do
366366 error ( __MODULE__ , error , meta , stack , context )
367367 end
368368
369+ @ doc """
370+ Marks a badpattern warnings.
371+ """
372+ def badpattern_warn ( expr , tag , stack , context ) do
373+ meta = error_meta ( expr , stack )
374+ error = { :badpattern , meta , expr , nil , tag , context }
375+ warn ( __MODULE__ , error , meta , stack , context )
376+ end
377+
369378 defp error_meta ( expr , stack ) do
370379 if meta = get_meta ( expr ) do
371380 meta ++ Keyword . take ( stack . meta , [ :generated , :line , :type_check ] )
@@ -1366,15 +1375,12 @@ defmodule Module.Types.Pattern do
13661375 # $ type tag = head_pattern() or match_pattern()
13671376 #
13681377 # $ typep head_pattern =
1369- # :for_reduce or : with_else or :fn or :default or
1378+ # :with_else or :fn or :default or
13701379 # {{:case | :try_else, meta, expr, type}, [arg], [previous]} or
1371- # {:receive | :try_catch, [arg], [previous]}
1380+ # {:for_reduce | : receive | :try_catch, [arg], [previous]}
13721381 #
13731382 # $ typep match_pattern =
13741383 # :with or :for or {:match, type}
1375- #
1376- # The match pattern ones have the whole expression instead
1377- # of a single pattern.
13781384 def format_diagnostic ( { :badpattern , meta , pattern_or_expr , index , tag , context } ) do
13791385 # TODO: stop passing pattern_or_expr as argument
13801386 { to_trace , message } = badpattern ( tag , pattern_or_expr , index )
@@ -1509,7 +1515,7 @@ defmodule Module.Types.Pattern do
15091515 end
15101516 end
15111517
1512- defp badpattern ( { op , args , previous } , _ , _ ) when op in [ :receive , :try_catch ] do
1518+ defp badpattern ( { op , args , previous } , _ , _ ) when op in [ :receive , :try_catch , :for_reduce ] do
15131519 { args ,
15141520 """
15151521 the following clause is redundant:
0 commit comments