diff options
author | Kostis Sagonas <[email protected]> | 2010-10-06 01:16:19 +0300 |
---|---|---|
committer | Kostis Sagonas <[email protected]> | 2010-10-06 01:16:19 +0300 |
commit | e041319e4a4c451c5ec090d2ea64f545aeaadb78 (patch) | |
tree | 03ceb0079e7624d11fbdda5c7124819082ff6f15 /lib/stdlib | |
parent | 3cfec17ff7aff97c5ec862a8b9e97d245849f9c3 (diff) | |
download | otp-e041319e4a4c451c5ec090d2ea64f545aeaadb78.tar.gz otp-e041319e4a4c451c5ec090d2ea64f545aeaadb78.tar.bz2 otp-e041319e4a4c451c5ec090d2ea64f545aeaadb78.zip |
Avoid errors for a badly formed export_type declarations
In the following program, erl_lint crashed with an erl_lint internal error.
With this patch it does not, but prints "bad export_type declaration" errors
instead.
-module(baz).
-export([test/0]).
-export_type(t/0).
-export_type([3.14]).
-type t() :: any().
test() -> 42.
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/src/erl_lint.erl | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl index 077621ac91..0c2d3db8ec 100644 --- a/lib/stdlib/src/erl_lint.erl +++ b/lib/stdlib/src/erl_lint.erl @@ -311,6 +311,8 @@ format_error({ill_defined_behaviour_callbacks,Behaviour}) -> %% --- types and specs --- format_error({singleton_typevar, Name}) -> io_lib:format("type variable ~w is only used once (is unbound)", [Name]); +format_error({bad_export_type, _ETs}) -> + io_lib:format("bad export_type declaration", []); format_error({duplicated_export_type, {T, A}}) -> io_lib:format("type ~w/~w already exported", [T, A]); format_error({undefined_type, {TypeName, Arity}}) -> @@ -1128,8 +1130,7 @@ export(Line, Es, #lint{exports = Es0, called = Called} = St0) -> export_type(Line, ETs, #lint{usage = Usage, exp_types = ETs0} = St0) -> UTs0 = Usage#usage.used_types, - {ETs1,UTs1,St1} = - foldl(fun (TA, {E,U,St2}) -> + try foldl(fun ({T,A}=TA, {E,U,St2}) when is_atom(T), is_integer(A) -> St = case gb_sets:is_element(TA, E) of true -> Warn = {duplicated_export_type,TA}, @@ -1139,8 +1140,13 @@ export_type(Line, ETs, #lint{usage = Usage, exp_types = ETs0} = St0) -> end, {gb_sets:add_element(TA, E), dict:store(TA, Line, U), St} end, - {ETs0,UTs0,St0}, ETs), - St1#lint{usage = Usage#usage{used_types = UTs1}, exp_types = ETs1}. + {ETs0,UTs0,St0}, ETs) of + {ETs1,UTs1,St1} -> + St1#lint{usage = Usage#usage{used_types = UTs1}, exp_types = ETs1} + catch + error:_ -> + add_error(Line, {bad_export_type, ETs}, St0) + end. -type import() :: {module(), [fa()]} | module(). -spec import(line(), import(), lint_state()) -> lint_state(). |