@@ -1032,18 +1032,42 @@ unsafe_to_atom(Binary, Line, Column, #elixir_tokenizer{existing_atoms_only=true}
1032
1032
try
1033
1033
{ok , binary_to_existing_atom (Binary , utf8 )}
1034
1034
catch
1035
- error :badarg -> {error , {? LOC (Line , Column ), " unsafe atom does not exist: " , elixir_utils :characters_to_list (Binary )}}
1035
+ error :badarg ->
1036
+ % Check if it's a UTF-8 issue by trying to convert to list
1037
+ elixir_utils :characters_to_list (Binary ),
1038
+ % If we get here, it's not a UTF-8 issue
1039
+ {error , {? LOC (Line , Column ), " unsafe atom does not exist: " , elixir_utils :characters_to_list (Binary )}}
1040
+ end ;
1041
+ unsafe_to_atom (Binary , Line , Column , # elixir_tokenizer {}) when is_binary (Binary ) ->
1042
+ try
1043
+ {ok , binary_to_atom (Binary , utf8 )}
1044
+ catch
1045
+ error :badarg ->
1046
+ % Try to convert using elixir_utils to get proper UnicodeConversionError
1047
+ elixir_utils :characters_to_list (Binary ),
1048
+ % If we get here, it's not a UTF-8 issue, so it's some other badarg
1049
+ {error , {? LOC (Line , Column ), " invalid atom: " , elixir_utils :characters_to_list (Binary )}}
1036
1050
end ;
1037
- unsafe_to_atom (Binary , _Line , _Column , # elixir_tokenizer {}) when is_binary (Binary ) ->
1038
- {ok , binary_to_atom (Binary , utf8 )};
1039
1051
unsafe_to_atom (List , Line , Column , # elixir_tokenizer {existing_atoms_only = true }) when is_list (List ) ->
1040
1052
try
1041
1053
{ok , list_to_existing_atom (List )}
1042
1054
catch
1043
- error :badarg -> {error , {? LOC (Line , Column ), " unsafe atom does not exist: " , List }}
1055
+ error :badarg ->
1056
+ % Try to convert using elixir_utils to get proper UnicodeConversionError
1057
+ elixir_utils :characters_to_binary (List ),
1058
+ % If we get here, it's not a UTF-8 issue
1059
+ {error , {? LOC (Line , Column ), " unsafe atom does not exist: " , List }}
1044
1060
end ;
1045
- unsafe_to_atom (List , _Line , _Column , # elixir_tokenizer {}) when is_list (List ) ->
1046
- {ok , list_to_atom (List )}.
1061
+ unsafe_to_atom (List , Line , Column , # elixir_tokenizer {}) when is_list (List ) ->
1062
+ try
1063
+ {ok , list_to_atom (List )}
1064
+ catch
1065
+ error :badarg ->
1066
+ % Try to convert using elixir_utils to get proper UnicodeConversionError
1067
+ elixir_utils :characters_to_binary (List ),
1068
+ % If we get here, it's not a UTF-8 issue, so it's some other badarg
1069
+ {error , {? LOC (Line , Column ), " invalid atom: " , List }}
1070
+ end .
1047
1071
1048
1072
collect_modifiers ([H | T ], Buffer ) when ? is_downcase (H ) or ? is_upcase (H ) or ? is_digit (H ) ->
1049
1073
collect_modifiers (T , [H | Buffer ]);
0 commit comments