control whether checking for type-equivalence generates warnings

This commit is contained in:
Vern Paxson 2021-02-27 10:55:19 -08:00
parent 45b9371e38
commit c7234713b1
2 changed files with 13 additions and 10 deletions

View file

@ -648,7 +648,7 @@ int FuncType::MatchesIndex(detail::ListExpr* const index) const
MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX;
} }
bool FuncType::CheckArgs(const TypePList* args, bool is_init) const bool FuncType::CheckArgs(const TypePList* args, bool is_init, bool do_warn) const
{ {
std::vector<TypePtr> as; std::vector<TypePtr> as;
as.reserve(args->length()); as.reserve(args->length());
@ -656,16 +656,17 @@ bool FuncType::CheckArgs(const TypePList* args, bool is_init) const
for ( auto a : *args ) for ( auto a : *args )
as.emplace_back(NewRef{}, a); as.emplace_back(NewRef{}, a);
return CheckArgs(as, is_init); return CheckArgs(as, is_init, do_warn);
} }
bool FuncType::CheckArgs(const std::vector<TypePtr>& args, bool FuncType::CheckArgs(const std::vector<TypePtr>& args,
bool is_init) const bool is_init, bool do_warn) const
{ {
const auto& my_args = arg_types->GetTypes(); const auto& my_args = arg_types->GetTypes();
if ( my_args.size() != args.size() ) if ( my_args.size() != args.size() )
{ {
if ( do_warn )
Warn(util::fmt("Wrong number of arguments for function. Expected %zu, got %zu.", Warn(util::fmt("Wrong number of arguments for function. Expected %zu, got %zu.",
args.size(), my_args.size())); args.size(), my_args.size()));
return false; return false;
@ -676,6 +677,7 @@ bool FuncType::CheckArgs(const std::vector<TypePtr>& args,
for ( size_t i = 0; i < my_args.size(); ++i ) for ( size_t i = 0; i < my_args.size(); ++i )
if ( ! same_type(args[i], my_args[i], is_init) ) if ( ! same_type(args[i], my_args[i], is_init) )
{ {
if ( do_warn )
Warn(util::fmt("Type mismatch in function argument #%zu. Expected %s, got %s.", Warn(util::fmt("Type mismatch in function argument #%zu. Expected %s, got %s.",
i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag()))); i, type_name(args[i]->Tag()), type_name(my_args[i]->Tag())));
success = false; success = false;
@ -1647,7 +1649,7 @@ bool same_type(const Type& arg_t1, const Type& arg_t2,
return false; return false;
} }
return ft1->CheckArgs(ft2->ParamList()->GetTypes(), is_init); return ft1->CheckArgs(ft2->ParamList()->GetTypes(), is_init, false);
} }
case TYPE_RECORD: case TYPE_RECORD:

View file

@ -447,9 +447,10 @@ public:
{ yield = nullptr; flavor = arg_flav; } { yield = nullptr; flavor = arg_flav; }
int MatchesIndex(detail::ListExpr* index) const override; int MatchesIndex(detail::ListExpr* index) const override;
bool CheckArgs(const TypePList* args, bool is_init = false) const; bool CheckArgs(const TypePList* args, bool is_init = false,
bool do_warn = true) const;
bool CheckArgs(const std::vector<TypePtr>& args, bool CheckArgs(const std::vector<TypePtr>& args,
bool is_init = false) const; bool is_init = false, bool do_warn = true) const;
const TypeListPtr& ParamList() const const TypeListPtr& ParamList() const
{ return arg_types; } { return arg_types; }