diff --git a/src/aeso_ast_infer_types.erl b/src/aeso_ast_infer_types.erl index 63e16df..de75101 100644 --- a/src/aeso_ast_infer_types.erl +++ b/src/aeso_ast_infer_types.erl @@ -1107,6 +1107,8 @@ check_typedef_sccs(Env, TypeMap, [{acyclic, Name} | SCCs], Acc) -> type_error({empty_record_definition, Ann, Name}), check_typedef_sccs(Env1, TypeMap, SCCs, Acc1); {record_t, Fields} -> + ets_insert(type_vars_variance, {Env#env.namespace ++ qname(D), + infer_type_vars_variance(Xs, Fields)}), %% check_type to get qualified name RecTy = check_type(Env1, app_t(Ann, D, Xs)), Env2 = check_fields(Env1, TypeMap, RecTy, Fields), @@ -1141,7 +1143,7 @@ check_typedef(Env, {variant_t, Cons}) -> infer_type_vars_variance(TypeParams, Cons) -> % args from all type constructors - FlatArgs = lists:flatten([Args || {constr_t, _, _, Args} <- Cons]), + FlatArgs = lists:flatten([Args || {constr_t, _, _, Args} <- Cons]) ++ [Type || {field_t, _, _, Type} <- Cons], Vs = lists:flatten([element(1, infer_type_vars_variance(Arg)) || Arg <- FlatArgs]), lists:map(fun({tvar, _, TVar}) -> @@ -1188,7 +1190,7 @@ infer_type_vars_variance({fun_t, _, [], [{tvar, _, TVar}], Res}) -> 1 -> {TVar, contravariant} end, {[Cur | TVVs], Depth + 1}; -infer_type_vars_variance({fun_t, _, [], [_Arg], Res}) -> +infer_type_vars_variance({fun_t, _, [], _, Res}) -> {X, Depth} = infer_type_vars_variance(Res), {X, Depth + 1}; infer_type_vars_variance({tvar, _, TVar}) -> diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index fc93db6..31197ce 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -990,6 +990,22 @@ failing_contracts() -> "Cannot unify `Animal` and `Cat`\n" "when checking the type of the expression `TK(f_a_to_c_to_u) : tk(Animal, Cat)` against the expected type `tk(Cat, Cat)`">> ]) + , ?TYPE_ERROR(polymorphism_variance_switching_records, + [<>, + <>, + <>, + <>, + <>]) ]. -define(Path(File), "code_errors/" ??File).