Skip to content

Commit 07e2ee8

Browse files
authored
Exempt event datatype from 'unused typedef' warning (#524)
1 parent 56b33ee commit 07e2ee8

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

src/aeso_ast_infer_types.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,8 +3478,14 @@ used_stateful(Fun) ->
34783478
%% Warnings (Unused type defs)
34793479

34803480
potential_unused_typedefs(Namespace, TypeDefs) ->
3481-
lists:map(fun({type_def, Ann, Id, Args, _}) ->
3482-
ets_insert(warnings, {unused_typedef, Ann, Namespace ++ qname(Id), length(Args)}) end, TypeDefs).
3481+
lists:map(
3482+
fun({type_def, _Ann, {id, _, "event"}, _Args, _}) ->
3483+
ok;
3484+
({type_def, Ann, Id, Args, _}) ->
3485+
ets_insert(warnings, {unused_typedef, Ann, Namespace ++ qname(Id), length(Args)})
3486+
end,
3487+
TypeDefs
3488+
).
34833489

34843490
used_typedef(TypeAliasId, Arity) ->
34853491
ets_match_delete(warnings, {unused_typedef, '_', qname(TypeAliasId), Arity}).

test/aeso_compiler_tests.erl

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -267,35 +267,35 @@ warnings() ->
267267
"The file `Triple.aes` is included but not used.">>,
268268
<<?PosW(13, 3)
269269
"The function `h` is defined but never used.">>,
270-
<<?PosW(19, 3)
270+
<<?PosW(25, 3)
271271
"The type `unused_type` is defined but never used.">>,
272-
<<?PosW(23, 54)
272+
<<?PosW(29, 54)
273273
"Negative spend.">>,
274-
<<?PosW(27, 9)
275-
"The definition of `x` shadows an older definition at line 26, column 9.">>,
276-
<<?PosW(30, 36)
274+
<<?PosW(33, 9)
275+
"The definition of `x` shadows an older definition at line 32, column 9.">>,
276+
<<?PosW(36, 36)
277277
"Division by zero.">>,
278-
<<?PosW(32, 3)
278+
<<?PosW(38, 3)
279279
"The function `unused_stateful` is unnecessarily marked as stateful.">>,
280-
<<?PosW(35, 31)
280+
<<?PosW(41, 31)
281281
"The variable `unused_arg` is defined but never used.">>,
282-
<<?PosW(36, 9)
282+
<<?PosW(42, 9)
283283
"The variable `unused_var` is defined but never used.">>,
284-
<<?PosW(41, 3)
284+
<<?PosW(47, 3)
285285
"The function `unused_function` is defined but never used.">>,
286-
<<?PosW(42, 3)
286+
<<?PosW(48, 3)
287287
"The function `recursive_unused_function` is defined but never used.">>,
288-
<<?PosW(43, 3)
288+
<<?PosW(49, 3)
289289
"The function `called_unused_function1` is defined but never used.">>,
290-
<<?PosW(44, 3)
290+
<<?PosW(50, 3)
291291
"The function `called_unused_function2` is defined but never used.">>,
292-
<<?PosW(48, 5)
292+
<<?PosW(54, 5)
293293
"Unused return value.">>,
294-
<<?PosW(60, 5)
294+
<<?PosW(66, 5)
295295
"The function `dec` is defined but never used.">>,
296-
<<?PosW(73, 9)
297-
"The definition of `const` shadows an older definition at line 70, column 3.">>,
298-
<<?PosW(84, 7)
296+
<<?PosW(79, 9)
297+
"The definition of `const` shadows an older definition at line 76, column 3.">>,
298+
<<?PosW(90, 7)
299299
"The constant `c` is defined but never used.">>
300300
]).
301301

@@ -860,35 +860,35 @@ failing_contracts() ->
860860
"The file `Triple.aes` is included but not used.">>,
861861
<<?Pos(13, 3)
862862
"The function `h` is defined but never used.">>,
863-
<<?Pos(19, 3)
863+
<<?Pos(25, 3)
864864
"The type `unused_type` is defined but never used.">>,
865-
<<?Pos(23, 54)
865+
<<?Pos(29, 54)
866866
"Negative spend.">>,
867-
<<?Pos(27, 9)
868-
"The definition of `x` shadows an older definition at line 26, column 9.">>,
869-
<<?Pos(30, 36)
867+
<<?Pos(33, 9)
868+
"The definition of `x` shadows an older definition at line 32, column 9.">>,
869+
<<?Pos(36, 36)
870870
"Division by zero.">>,
871-
<<?Pos(32, 3)
871+
<<?Pos(38, 3)
872872
"The function `unused_stateful` is unnecessarily marked as stateful.">>,
873-
<<?Pos(35, 31)
873+
<<?Pos(41, 31)
874874
"The variable `unused_arg` is defined but never used.">>,
875-
<<?Pos(36, 9)
875+
<<?Pos(42, 9)
876876
"The variable `unused_var` is defined but never used.">>,
877-
<<?Pos(41, 3)
877+
<<?Pos(47, 3)
878878
"The function `unused_function` is defined but never used.">>,
879-
<<?Pos(42, 3)
879+
<<?Pos(48, 3)
880880
"The function `recursive_unused_function` is defined but never used.">>,
881-
<<?Pos(43, 3)
881+
<<?Pos(49, 3)
882882
"The function `called_unused_function1` is defined but never used.">>,
883-
<<?Pos(44, 3)
883+
<<?Pos(50, 3)
884884
"The function `called_unused_function2` is defined but never used.">>,
885-
<<?Pos(48, 5)
885+
<<?Pos(54, 5)
886886
"Unused return value.">>,
887-
<<?Pos(60, 5)
887+
<<?Pos(66, 5)
888888
"The function `dec` is defined but never used.">>,
889-
<<?Pos(73, 9)
890-
"The definition of `const` shadows an older definition at line 70, column 3.">>,
891-
<<?Pos(84, 7)
889+
<<?Pos(79, 9)
890+
"The definition of `const` shadows an older definition at line 76, column 3.">>,
891+
<<?Pos(90, 7)
892892
"The constant `c` is defined but never used.">>
893893
])
894894
, ?TYPE_ERROR(polymorphism_contract_interface_recursive,

test/contracts/warnings.aes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ namespace UnusedNamespace =
1212
// Unused
1313
private function h() = 3
1414

15+
contract interface Eventer =
16+
datatype event = RemoteEvent(int)
17+
entrypoint emitEvents : () => unit
18+
1519
main contract Warnings =
1620

21+
datatype event = Event(int)
22+
1723
type state = int
1824

1925
type unused_type = bool

0 commit comments

Comments
 (0)