Match only with function name and without typesig
This commit is contained in:
parent
06879fdf73
commit
2a55823633
@ -1467,33 +1467,31 @@ check_reserved_entrypoints(Funs) ->
|
|||||||
check_fundecl(Env, {fun_decl, Ann, Id = {id, _, Name}, Type = {fun_t, _, _, _, _}}) ->
|
check_fundecl(Env, {fun_decl, Ann, Id = {id, _, Name}, Type = {fun_t, _, _, _, _}}) ->
|
||||||
Type1 = {fun_t, _, Named, Args, Ret} = check_type(Env, Type),
|
Type1 = {fun_t, _, Named, Args, Ret} = check_type(Env, Type),
|
||||||
TypeSig = {type_sig, Ann, none, Named, Args, Ret},
|
TypeSig = {type_sig, Ann, none, Named, Args, Ret},
|
||||||
register_implementation(Env, Name, TypeSig),
|
register_implementation(Env, Name),
|
||||||
{{Name, TypeSig}, {fun_decl, Ann, Id, Type1}};
|
{{Name, TypeSig}, {fun_decl, Ann, Id, Type1}};
|
||||||
check_fundecl(Env, {fun_decl, Ann, Id = {id, _, Name}, Type}) ->
|
check_fundecl(Env, {fun_decl, Ann, Id = {id, _, Name}, Type}) ->
|
||||||
type_error({fundecl_must_have_funtype, Ann, Id, Type}),
|
type_error({fundecl_must_have_funtype, Ann, Id, Type}),
|
||||||
{{Name, {type_sig, Ann, none, [], [], Type}}, check_type(Env, Type)}.
|
{{Name, {type_sig, Ann, none, [], [], Type}}, check_type(Env, Type)}.
|
||||||
|
|
||||||
%% Register the function FunName with the signature FunSig by deleting it from
|
%% Register the function FunName as implemented by deleting it from the functions
|
||||||
%% the functions to be implemented if it is included there, or return ok otherwise.
|
%% to be implemented table if it is included there, or return true otherwise.
|
||||||
-spec register_implementation(env(), FunName, FunSig) -> true when
|
-spec register_implementation(env(), FunName) -> true | no_return() when
|
||||||
FunName :: string(),
|
FunName :: string().
|
||||||
FunSig :: typesig().
|
register_implementation(Env, Name) ->
|
||||||
register_implementation(Env, Name, Sig) ->
|
|
||||||
case ets_lookup(functions_to_implement, Name) of
|
case ets_lookup(functions_to_implement, Name) of
|
||||||
[{Name, _, {fun_decl, _, _, DeclType}}] ->
|
[{Name, _, {fun_decl, _, _, DeclType}}] ->
|
||||||
case unify(Env#env{unify_throws = false}, typesig_to_fun_t(Sig), DeclType, unknown) of
|
ets_delete(functions_to_implement, Name);
|
||||||
true -> ets_delete(functions_to_implement, Name);
|
[] ->
|
||||||
false -> true
|
true;
|
||||||
end;
|
_ ->
|
||||||
[] -> true;
|
error("Ets set has multiple keys")
|
||||||
_ -> error("Ets set has multiple keys")
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
infer_nonrec(Env, LetFun) ->
|
infer_nonrec(Env, LetFun) ->
|
||||||
create_constraints(),
|
create_constraints(),
|
||||||
NewLetFun = {{FunName, FunSig}, _} = infer_letfun(Env, LetFun),
|
NewLetFun = {{FunName, FunSig}, _} = infer_letfun(Env, LetFun),
|
||||||
check_special_funs(Env, NewLetFun),
|
check_special_funs(Env, NewLetFun),
|
||||||
register_implementation(Env, FunName, FunSig),
|
register_implementation(Env, FunName),
|
||||||
solve_then_destroy_and_report_unsolved_constraints(Env),
|
solve_then_destroy_and_report_unsolved_constraints(Env),
|
||||||
Result = {TypeSig, _} = instantiate(NewLetFun),
|
Result = {TypeSig, _} = instantiate(NewLetFun),
|
||||||
print_typesig(TypeSig),
|
print_typesig(TypeSig),
|
||||||
@ -1523,7 +1521,7 @@ infer_letrec(Env, Defs) ->
|
|||||||
Inferred =
|
Inferred =
|
||||||
[ begin
|
[ begin
|
||||||
Res = {{Name, TypeSig}, _} = infer_letfun(ExtendEnv, LF),
|
Res = {{Name, TypeSig}, _} = infer_letfun(ExtendEnv, LF),
|
||||||
register_implementation(Env, Name, TypeSig),
|
register_implementation(Env, Name),
|
||||||
Got = proplists:get_value(Name, Funs),
|
Got = proplists:get_value(Name, Funs),
|
||||||
Expect = typesig_to_fun_t(TypeSig),
|
Expect = typesig_to_fun_t(TypeSig),
|
||||||
unify(Env, Got, Expect, {check_typesig, Name, Got, Expect}),
|
unify(Env, Got, Expect, {check_typesig, Name, Got, Expect}),
|
||||||
|
@ -849,8 +849,10 @@ failing_contracts() ->
|
|||||||
"Trying to implement or extend an undefined interface `Z`">>
|
"Trying to implement or extend an undefined interface `Z`">>
|
||||||
])
|
])
|
||||||
, ?TYPE_ERROR(polymorphism_contract_interface_same_name_different_type,
|
, ?TYPE_ERROR(polymorphism_contract_interface_same_name_different_type,
|
||||||
[<<?Pos(4,20)
|
[<<?Pos(9,5)
|
||||||
"Unimplemented function `f` from the interface `I1` in the contract `I2`">>])
|
"Duplicate definitions of `f` at\n"
|
||||||
|
" - line 8, column 5\n"
|
||||||
|
" - line 9, column 5">>])
|
||||||
, ?TYPE_ERROR(polymorphism_contract_missing_implementation,
|
, ?TYPE_ERROR(polymorphism_contract_missing_implementation,
|
||||||
[<<?Pos(4,20)
|
[<<?Pos(4,20)
|
||||||
"Unimplemented function `f` from the interface `I1` in the contract `I2`">>
|
"Unimplemented function `f` from the interface `I1` in the contract `I2`">>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user