Nicer error for missing event type
This commit is contained in:
parent
d8adfce465
commit
97d58fcacd
@ -205,18 +205,18 @@ bind_state(Env) ->
|
||||
{S, _} -> {qid, Ann, S};
|
||||
false -> Unit
|
||||
end,
|
||||
Event =
|
||||
case lookup_type(Env, {id, Ann, "event"}) of
|
||||
{E, _} -> {qid, Ann, E};
|
||||
false -> {id, Ann, "event"} %% will cause type error if used(?)
|
||||
end,
|
||||
Env1 = bind_funs([{"state", State},
|
||||
{"put", {type_sig, [stateful | Ann], [], [State], Unit}}], Env),
|
||||
|
||||
%% We bind Chain.event in a local 'Chain' namespace.
|
||||
pop_scope(
|
||||
bind_fun("event", {fun_t, Ann, [], [Event], Unit},
|
||||
push_scope(namespace, {con, Ann, "Chain"}, Env1))).
|
||||
case lookup_type(Env, {id, Ann, "event"}) of
|
||||
{E, _} ->
|
||||
%% We bind Chain.event in a local 'Chain' namespace.
|
||||
Event = {qid, Ann, E},
|
||||
pop_scope(
|
||||
bind_fun("event", {fun_t, Ann, [], [Event], Unit},
|
||||
push_scope(namespace, {con, Ann, "Chain"}, Env1)));
|
||||
false -> Env1
|
||||
end.
|
||||
|
||||
-spec bind_field(name(), field_info(), env()) -> env().
|
||||
bind_field(X, Info, Env = #env{ fields = Fields }) ->
|
||||
@ -2112,7 +2112,12 @@ mk_error({cannot_unify, A, B, When}) ->
|
||||
mk_t_err(Pos, Msg, Ctxt);
|
||||
mk_error({unbound_variable, Id}) ->
|
||||
Msg = io_lib:format("Unbound variable ~s at ~s\n", [pp(Id), pp_loc(Id)]),
|
||||
mk_t_err(pos(Id), Msg);
|
||||
case Id of
|
||||
{qid, _, ["Chain", "event"]} ->
|
||||
Cxt = "Did you forget to define the event type?",
|
||||
mk_t_err(pos(Id), Msg, Cxt);
|
||||
_ -> mk_t_err(pos(Id), Msg)
|
||||
end;
|
||||
mk_error({undefined_field, Id}) ->
|
||||
Msg = io_lib:format("Unbound field ~s at ~s\n", [pp(Id), pp_loc(Id)]),
|
||||
mk_t_err(pos(Id), Msg);
|
||||
|
@ -496,6 +496,10 @@ failing_contracts() ->
|
||||
"and cannot be called from the contract code.">>])
|
||||
, ?TEST(bad_top_level_decl,
|
||||
[<<?Pos(1, 1) "The definition of 'square' must appear inside a contract or namespace.">>])
|
||||
, ?TEST(missing_event_type,
|
||||
[<<?Pos(3, 5)
|
||||
"Unbound variable Chain.event at line 3, column 5\n"
|
||||
"Did you forget to define the event type?">>])
|
||||
].
|
||||
|
||||
-define(Path(File), "code_errors/" ??File).
|
||||
|
3
test/contracts/missing_event_type.aes
Normal file
3
test/contracts/missing_event_type.aes
Normal file
@ -0,0 +1,3 @@
|
||||
contract MissingEventType =
|
||||
entrypoint main() =
|
||||
Chain.event("MAIN")
|
Loading…
x
Reference in New Issue
Block a user