aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-03-16 15:42:15 +0100
committerBjörn Gustavsson <[email protected]>2017-03-16 16:31:01 +0100
commitfc3b5a1a287780bced92f2f1a1744bf86d7b9ba2 (patch)
treea1050511e6c2eadb85a8c01a046fcdcef3d2f57a /lib/stdlib/src
parent6a0ca45bb465150ba47d057ecd6c75681b790aab (diff)
downloadotp-fc3b5a1a287780bced92f2f1a1744bf86d7b9ba2.tar.gz
otp-fc3b5a1a287780bced92f2f1a1744bf86d7b9ba2.tar.bz2
otp-fc3b5a1a287780bced92f2f1a1744bf86d7b9ba2.zip
Don't allow module names with non-latin1 characters
In OTP 20, all Unicode characters are allowed in atoms. However, we have decided that we will not allow non-latin1 characters in module names in OTP 20. This restriction may be lifted in a future major release of OTP. Enforce the restriction in erl_lint, so that it will be a compilation error to have a module name containing non-latin1 characters. That means that tools such as debugger, xref, dialyzer, syntax_tools, and so on, do not have to be modified to handle non-latin1 module names.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/erl_lint.erl15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 0ffca0886f..0789f5dfb7 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -156,6 +156,8 @@ format_error(pmod_unsupported) ->
"parameterized modules are no longer supported";
%% format_error({redefine_mod_import, M, P}) ->
%% io_lib:format("module '~s' already imported from package '~s'", [M, P]);
+format_error(non_latin1_module_unsupported) ->
+ "module names with non-latin1 characters are not supported";
format_error(invalid_call) ->
"invalid function call";
@@ -733,9 +735,15 @@ form(Form, #lint{state=State}=St) ->
start_state({attribute,Line,module,{_,_}}=Form, St0) ->
St1 = add_error(Line, pmod_unsupported, St0),
attribute_state(Form, St1#lint{state=attribute});
-start_state({attribute,_,module,M}, St0) ->
+start_state({attribute,Line,module,M}, St0) ->
St1 = St0#lint{module=M},
- St1#lint{state=attribute};
+ St2 = St1#lint{state=attribute},
+ case is_non_latin1_name(M) of
+ true ->
+ add_error(Line, non_latin1_module_unsupported, St2);
+ false ->
+ St2
+ end;
start_state(Form, St) ->
Anno = case Form of
{eof, L} -> erl_anno:new(L);
@@ -745,6 +753,9 @@ start_state(Form, St) ->
St1 = add_error(Anno, undefined_module, St),
attribute_state(Form, St1#lint{state=attribute}).
+is_non_latin1_name(Name) ->
+ lists:any(fun(C) -> C > 255 end, atom_to_list(Name)).
+
%% attribute_state(Form, State) ->
%% State'