diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 0c319f4..b288961 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -1098,6 +1098,7 @@ check_typedef_sccs(Env, TypeMap, [{acyclic, Name} | SCCs], Acc) -> case maps:get(Name, TypeMap, undefined) of undefined -> check_typedef_sccs(Env, TypeMap, SCCs, Acc); %% Builtin type {type_def, Ann, D, Xs, Def0} -> + check_parameterizable(D, Xs), Def = check_event(Env, Name, Ann, check_typedef(bind_tvars(Xs, Env), Def0)), Acc1 = [{type_def, Ann, D, Xs, Def} | Acc], Env1 = bind_type(Name, Ann, {Xs, Def}, Env), @@ -1353,6 +1354,13 @@ check_fields(Env, TypeMap, RecTy, [{field_t, Ann, Id, Type} | Fields]) -> Env1 = bind_field(name(Id), #field_info{ ann = Ann, kind = record, field_t = Type, record_t = RecTy }, Env), check_fields(Env1, TypeMap, RecTy, Fields). +check_parameterizable({id, Ann, "event"}, [_ | _]) -> + type_error({parameterized_event, Ann}); +check_parameterizable({id, Ann, "state"}, [_ | _]) -> + type_error({parameterized_state, Ann}); +check_parameterizable(_Name, _Xs) -> + ok. + check_event(Env, "event", Ann, Def) -> case Def of {variant_t, Cons} -> @@ -3490,6 +3498,12 @@ mk_error({referencing_undefined_interface, InterfaceId}) -> mk_error({missing_definition, Id}) -> Msg = io_lib:format("Missing definition of function `~s`", [name(Id)]), mk_t_err(pos(Id), Msg); +mk_error({parameterized_state, Ann}) -> + Msg = "The state type cannot be parameterized", + mk_t_err(pos(Ann), Msg); +mk_error({parameterized_event, Ann}) -> + Msg = "The event type cannot be parameterized", + mk_t_err(pos(Ann), Msg); mk_error(Err) -> Msg = io_lib:format("Unknown error: ~p", [Err]), mk_t_err(pos(0, 0), Msg). diff --git a/src/aeso_code_errors.erl b/src/aeso_code_errors.erl index ea36803..66997a6 100644 --- a/src/aeso_code_errors.erl +++ b/src/aeso_code_errors.erl @@ -18,12 +18,6 @@ format({missing_init_function, Con}) -> Msg = io_lib:format("Missing init function for the contract '~s'.", [pp_expr(Con)]), Cxt = "The 'init' function can only be omitted if the state type is 'unit'.", mk_err(pos(Con), Msg, Cxt); -format({parameterized_state, Decl}) -> - Msg = "The state type cannot be parameterized.", - mk_err(pos(Decl), Msg); -format({parameterized_event, Decl}) -> - Msg = "The event type cannot be parameterized.", - mk_err(pos(Decl), Msg); format({invalid_entrypoint, Why, Ann, {id, _, Name}, Thing}) -> What = case Why of higher_order -> "higher-order (contains function types)"; polymorphic -> "polymorphic (contains type variables)" end, diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index 9be8d9c..1b26101 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -973,7 +973,8 @@ failing_contracts() -> "when checking the type of the pattern `r10 : rec_inv(Animal)` against the expected type `Main.rec_inv(Cat)`">>, <>]) + "when checking the type of the pattern `r11 : rec_inv(Cat)` against the expected type `Main.rec_inv(Animal)`">> + ]) , ?TYPE_ERROR(polymorphism_variance_switching_oracles, [< "when checking the type of the pattern `q14 : oracle_query(Cat, Cat)` against the expected type `oracle_query(Animal, Cat)`">>, <>]) + "when checking the type of the pattern `q15 : oracle_query(Cat, Cat)` against the expected type `oracle_query(Cat, Animal)`">> + ]) , ?TYPE_ERROR(missing_definition, [<>]) + "Missing definition of function `foo`">> + ]) , ?TYPE_ERROR(child_with_decls, [<>]) + "Missing definition of function `f`">> + ]) + , ?TYPE_ERROR(parameterised_state, + [<> + ]) + , ?TYPE_ERROR(parameterised_event, + [<> + ]) ]. -define(Path(File), "code_errors/" ??File). @@ -1042,10 +1054,6 @@ failing_code_gen_contracts() -> , ?FATE_ERR(missing_init_function, 1, 10, "Missing init function for the contract 'MissingInitFunction'.\n" "The 'init' function can only be omitted if the state type is 'unit'.") - , ?FATE_ERR(parameterised_state, 3, 8, - "The state type cannot be parameterized.") - , ?FATE_ERR(parameterised_event, 3, 12, - "The event type cannot be parameterized.") , ?FATE_ERR(polymorphic_aens_resolve, 4, 5, "Invalid return type of AENS.resolve:\n" " 'a\n" diff --git a/test/contracts/code_errors/parameterised_event.aes b/test/contracts/parameterised_event.aes similarity index 100% rename from test/contracts/code_errors/parameterised_event.aes rename to test/contracts/parameterised_event.aes diff --git a/test/contracts/code_errors/parameterised_state.aes b/test/contracts/parameterised_state.aes similarity index 100% rename from test/contracts/code_errors/parameterised_state.aes rename to test/contracts/parameterised_state.aes