Ban empty record declarations

This commit is contained in:
Gaith Hallak 2022-05-23 20:33:13 +04:00
parent a894876f56
commit af2fe4515c
4 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
``` ```
### Changed ### Changed
- Error messages have been restructured (less newlines) to provide more unified errors. Also `pp_oneline/1` has been added. - Error messages have been restructured (less newlines) to provide more unified errors. Also `pp_oneline/1` has been added.
- Ban empty record declarations (e.g. `record r = {}` would give an error).
### Removed ### Removed
- Support for AEVM has been entirely wiped - Support for AEVM has been entirely wiped

View File

@ -1018,6 +1018,9 @@ check_typedef_sccs(Env, TypeMap, [{acyclic, Name} | SCCs], Acc) ->
Env1 = bind_type(Name, Ann, {Xs, Def}, Env), Env1 = bind_type(Name, Ann, {Xs, Def}, Env),
case Def of case Def of
{alias_t, _} -> check_typedef_sccs(Env1, TypeMap, SCCs, Acc1); {alias_t, _} -> check_typedef_sccs(Env1, TypeMap, SCCs, Acc1);
{record_t, []} ->
type_error({empty_record_declaration, Ann, Name}),
check_typedef_sccs(Env1, TypeMap, SCCs, Acc1);
{record_t, Fields} -> {record_t, Fields} ->
%% check_type to get qualified name %% check_type to get qualified name
RecTy = check_type(Env1, app_t(Ann, D, Xs)), RecTy = check_type(Env1, app_t(Ann, D, Xs)),
@ -3279,6 +3282,9 @@ mk_error({using_undefined_namespace_parts, Ann, Namespace, Parts}) ->
mk_error({unknown_warning, Warning}) -> mk_error({unknown_warning, Warning}) ->
Msg = io_lib:format("Trying to report unknown warning: ~p", [Warning]), Msg = io_lib:format("Trying to report unknown warning: ~p", [Warning]),
mk_t_err(pos(0, 0), Msg); mk_t_err(pos(0, 0), Msg);
mk_error({empty_record_declaration, Ann, Name}) ->
Msg = io_lib:format("Empty record declarations are not allowed. Cannot declare the record `~s`", [Name]),
mk_t_err(pos(Ann), Msg);
mk_error(Err) -> mk_error(Err) ->
Msg = io_lib:format("Unknown error: ~p", [Err]), Msg = io_lib:format("Unknown error: ~p", [Err]),
mk_t_err(pos(0, 0), Msg). mk_t_err(pos(0, 0), Msg).

View File

@ -791,6 +791,10 @@ failing_contracts() ->
"when checking the type of the expression `\"y\" : string` " "when checking the type of the expression `\"y\" : string` "
"against the expected type `bool`">> "against the expected type `bool`">>
]) ])
, ?TYPE_ERROR(empty_record_declaration,
[<<?Pos(2,5)
"Empty record declarations are not allowed. Cannot declare the record `r`">>
])
, ?TYPE_ERROR(warnings, , ?TYPE_ERROR(warnings,
[<<?Pos(0, 0) [<<?Pos(0, 0)
"The file `Triple.aes` is included but not used.">>, "The file `Triple.aes` is included but not used.">>,

View File

@ -0,0 +1,3 @@
contract C =
record r = {}
entrypoint init() = ()