Ban empty record definitions (#384)
* Ban empty record declarations * Use definition instead of declaration * Fix the failing test
This commit is contained in:
parent
a894876f56
commit
b0e6418161
@ -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 definitions (e.g. `record r = {}` would give an error).
|
||||||
### Removed
|
### Removed
|
||||||
- Support for AEVM has been entirely wiped
|
- Support for AEVM has been entirely wiped
|
||||||
|
|
||||||
|
@ -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_definition, 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_definition, Ann, Name}) ->
|
||||||
|
Msg = io_lib:format("Empty record definitions are not allowed. Cannot define 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).
|
||||||
|
@ -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_definition,
|
||||||
|
[<<?Pos(2,5)
|
||||||
|
"Empty record definitions are not allowed. Cannot define 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.">>,
|
||||||
|
3
test/contracts/empty_record_definition.aes
Normal file
3
test/contracts/empty_record_definition.aes
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
contract C =
|
||||||
|
record r = {}
|
||||||
|
entrypoint init() = ()
|
Loading…
x
Reference in New Issue
Block a user