Make 'indexed' keyword optional
This commit is contained in:
parent
33dbeeefad
commit
5c98317a5a
@ -738,25 +738,23 @@ check_event(Env, "event", Ann, Def) ->
|
|||||||
check_event(_Env, _Name, _Ann, Def) -> Def.
|
check_event(_Env, _Name, _Ann, Def) -> Def.
|
||||||
|
|
||||||
check_event_con(Env, {constr_t, Ann, Con, Args}) ->
|
check_event_con(Env, {constr_t, Ann, Con, Args}) ->
|
||||||
IsIndexed = fun(T) -> case aeso_syntax:get_ann(indexed, T, false) of
|
IsIndexed = fun(T) ->
|
||||||
true -> indexed;
|
T1 = unfold_types_in_type(Env, T),
|
||||||
false -> notindexed
|
%% `indexed` is optional but if used it has to be correctly used
|
||||||
end end,
|
case {is_word_type(T1), is_string_type(T1), aeso_syntax:get_ann(indexed, T, false)} of
|
||||||
|
{true, _, _} -> indexed;
|
||||||
|
{false, true, true} -> type_error({indexed_type_must_be_word, T, T1});
|
||||||
|
{false, true, _} -> notindexed;
|
||||||
|
{false, false, _} -> type_error({event_arg_type_word_or_string, T, T1}), error
|
||||||
|
end
|
||||||
|
end,
|
||||||
Indices = lists:map(IsIndexed, Args),
|
Indices = lists:map(IsIndexed, Args),
|
||||||
Indexed = [ T || T <- Args, IsIndexed(T) == indexed ],
|
Indexed = [ T || T <- Args, IsIndexed(T) == indexed ],
|
||||||
NonIndexed = Args -- Indexed,
|
NonIndexed = Args -- Indexed,
|
||||||
[ check_event_arg_type(Env, Ix, Type) || {Ix, Type} <- lists:zip(Indices, Args) ],
|
|
||||||
[ type_error({event_0_to_3_indexed_values, Con}) || length(Indexed) > 3 ],
|
[ type_error({event_0_to_3_indexed_values, Con}) || length(Indexed) > 3 ],
|
||||||
[ type_error({event_0_to_1_string_values, Con}) || length(NonIndexed) > 1 ],
|
[ type_error({event_0_to_1_string_values, Con}) || length(NonIndexed) > 1 ],
|
||||||
{constr_t, [{indices, Indices} | Ann], Con, Args}.
|
{constr_t, [{indices, Indices} | Ann], Con, Args}.
|
||||||
|
|
||||||
check_event_arg_type(Env, Ix, Type0) ->
|
|
||||||
Type = unfold_types_in_type(Env, Type0),
|
|
||||||
case Ix of
|
|
||||||
indexed -> [ type_error({indexed_type_must_be_word, Type0, Type}) || not is_word_type(Type) ];
|
|
||||||
notindexed -> [ type_error({payload_type_must_be_string, Type0, Type}) || not is_string_type(Type) ]
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% Not so nice.
|
%% Not so nice.
|
||||||
is_word_type({id, _, Name}) ->
|
is_word_type({id, _, Name}) ->
|
||||||
lists:member(Name, ["int", "address", "hash", "bits", "bool"]);
|
lists:member(Name, ["int", "address", "hash", "bits", "bool"]);
|
||||||
|
@ -211,16 +211,11 @@ failing_contracts() ->
|
|||||||
, {"namespace_clash",
|
, {"namespace_clash",
|
||||||
[<<"The contract Call (at line 4, column 10) has the same name as a namespace at (builtin location)">>]}
|
[<<"The contract Call (at line 4, column 10) has the same name as a namespace at (builtin location)">>]}
|
||||||
, {"bad_events",
|
, {"bad_events",
|
||||||
[<<"The payload type int (at line 10, column 30) should be string">>,
|
[<<"The indexed type string (at line 9, column 25) is not a word type">>,
|
||||||
<<"The payload type alias_address (at line 12, column 30) equals address but it should be string">>,
|
<<"The indexed type alias_string (at line 10, column 25) equals string which is not a word type">>]}
|
||||||
<<"The indexed type string (at line 9, column 25) is not a word type">>,
|
|
||||||
<<"The indexed type alias_string (at line 11, column 25) equals string which is not a word type">>]}
|
|
||||||
, {"bad_events2",
|
, {"bad_events2",
|
||||||
[<<"The event constructor BadEvent1 (at line 9, column 7) has too many non-indexed values (max 1)">>,
|
[<<"The event constructor BadEvent1 (at line 9, column 7) has too many non-indexed values (max 1)">>,
|
||||||
<<"The event constructor BadEvent2 (at line 10, column 7) has too many indexed values (max 3)">>,
|
<<"The event constructor BadEvent2 (at line 10, column 7) has too many indexed values (max 3)">>]}
|
||||||
<<"The event constructor BadEvent3 (at line 11, column 7) has too many non-indexed values (max 1)">>,
|
|
||||||
<<"The payload type address (at line 11, column 17) should be string">>,
|
|
||||||
<<"The payload type int (at line 11, column 26) should be string">>]}
|
|
||||||
, {"type_clash",
|
, {"type_clash",
|
||||||
[<<"Cannot unify int\n"
|
[<<"Cannot unify int\n"
|
||||||
" and string\n"
|
" and string\n"
|
||||||
|
@ -6,10 +6,8 @@ contract Events =
|
|||||||
datatype event =
|
datatype event =
|
||||||
Event1(indexed alias_int, indexed int, string)
|
Event1(indexed alias_int, indexed int, string)
|
||||||
| Event2(alias_string, indexed alias_address)
|
| Event2(alias_string, indexed alias_address)
|
||||||
| BadEvent1(indexed string, string)
|
| BadEvent1(indexed string)
|
||||||
| BadEvent2(indexed int, int)
|
| BadEvent2(indexed alias_string)
|
||||||
| BadEvent3(indexed alias_string, string)
|
|
||||||
| BadEvent4(indexed int, alias_address)
|
|
||||||
|
|
||||||
function f1(x : int, y : string) =
|
function f1(x : int, y : string) =
|
||||||
Chain.event(Event1(x, x+1, y))
|
Chain.event(Event1(x, x+1, y))
|
||||||
|
@ -8,7 +8,6 @@ contract Events =
|
|||||||
| Event2(alias_string, indexed alias_address)
|
| Event2(alias_string, indexed alias_address)
|
||||||
| BadEvent1(string, string)
|
| BadEvent1(string, string)
|
||||||
| BadEvent2(indexed int, indexed int, indexed int, indexed address)
|
| BadEvent2(indexed int, indexed int, indexed int, indexed address)
|
||||||
| BadEvent3(address, int)
|
|
||||||
|
|
||||||
function f1(x : int, y : string) =
|
function f1(x : int, y : string) =
|
||||||
Chain.event(Event1(x, x+1, y))
|
Chain.event(Event1(x, x+1, y))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user