@@ -5765,8 +5765,11 @@ defmodule Kernel do
5765
5765
"only a single when clause is allowed"
5766
5766
5767
5767
{ call , impls } ->
5768
- case Macro . decompose_call ( call ) do
5769
- { _name , args } ->
5768
+ case decompose_args ( call ) do
5769
+ :error ->
5770
+ raise ArgumentError , "invalid syntax in defguard #{ Macro . to_string ( call ) } "
5771
+
5772
+ args ->
5770
5773
validate_variable_only_args! ( call , args )
5771
5774
5772
5775
macro_definition =
@@ -5788,13 +5791,20 @@ defmodule Kernel do
5788
5791
Elixir.Kernel . @ ( doc ( guard: true ) )
5789
5792
unquote ( macro_definition )
5790
5793
end
5791
-
5792
- _invalid_definition ->
5793
- raise ArgumentError , "invalid syntax in defguard #{ Macro . to_string ( call ) } "
5794
5794
end
5795
5795
end
5796
5796
end
5797
5797
5798
+ defp decompose_args ( { name , _ , args } ) when is_atom ( name ) and is_atom ( args ) , do: [ ]
5799
+
5800
+ defp decompose_args ( { name , _ , args } ) when is_atom ( name ) and is_list ( args ) , do: args
5801
+
5802
+ defp decompose_args ( { { :unquote , _ , _ } , _ , args } ) when is_atom ( args ) , do: [ ]
5803
+
5804
+ defp decompose_args ( { { :unquote , _ , _ } , _ , args } ) when is_list ( args ) , do: args
5805
+
5806
+ defp decompose_args ( _ ) , do: :error
5807
+
5798
5808
defp validate_variable_only_args! ( call , args ) do
5799
5809
Enum . each ( args , fn
5800
5810
{ ref , _meta , context } when is_atom ( ref ) and is_atom ( context ) ->
0 commit comments