mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Fix function type-equivalence requiring same param names, addresses #957
This commit is contained in:
parent
8ee4382721
commit
2293443ea0
4 changed files with 48 additions and 7 deletions
|
@ -712,7 +712,7 @@ int FuncType::MatchesIndex(ListExpr*& index) const
|
|||
MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX;
|
||||
}
|
||||
|
||||
int FuncType::CheckArgs(const type_list* args) const
|
||||
int FuncType::CheckArgs(const type_list* args, bool is_init) const
|
||||
{
|
||||
const type_list* my_args = arg_types->Types();
|
||||
|
||||
|
@ -720,7 +720,7 @@ int FuncType::CheckArgs(const type_list* args) const
|
|||
return 0;
|
||||
|
||||
for ( int i = 0; i < my_args->length(); ++i )
|
||||
if ( ! same_type((*args)[i], (*my_args)[i]) )
|
||||
if ( ! same_type((*args)[i], (*my_args)[i], is_init) )
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
@ -1722,7 +1722,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init)
|
|||
return 0;
|
||||
}
|
||||
|
||||
return same_type(ft1->Args(), ft2->Args(), is_init);
|
||||
return ft1->CheckArgs(ft2->ArgTypes()->Types(), is_init);
|
||||
}
|
||||
|
||||
case TYPE_RECORD:
|
||||
|
|
|
@ -370,11 +370,9 @@ public:
|
|||
{ Unref(yield); yield = 0; flavor = arg_flav; }
|
||||
|
||||
int MatchesIndex(ListExpr*& index) const;
|
||||
int CheckArgs(const type_list* args) const;
|
||||
int CheckArgs(const type_list* args, bool is_init = false) const;
|
||||
|
||||
TypeList* ArgTypes() { return arg_types; }
|
||||
|
||||
ID* GetReturnValueID() const;
|
||||
TypeList* ArgTypes() const { return arg_types; }
|
||||
|
||||
void Describe(ODesc* d) const;
|
||||
void DescribeReST(ODesc* d) const;
|
||||
|
|
4
testing/btest/Baseline/language.func-assignment/out
Normal file
4
testing/btest/Baseline/language.func-assignment/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
Brogrammers, like bowties, are cool. Brogrammers, like bowties, are cool. Brogrammers, like bowties, are cool.
|
||||
Brogrammers, like bowties, are cool. Brogrammers, like bowties, are cool.
|
||||
BROGRAMMERS, LIKE BOWTIES, ARE COOL.
|
||||
BROGRAMMERS, LIKE BOWTIES, ARE COOL.
|
39
testing/btest/language/func-assignment.bro
Normal file
39
testing/btest/language/func-assignment.bro
Normal file
|
@ -0,0 +1,39 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
function double_string(s: string): string
|
||||
{
|
||||
return string_cat(s, " ", s);
|
||||
}
|
||||
|
||||
function triple_string(str: string): string
|
||||
{
|
||||
return string_cat(str, " ", str, " ", str);
|
||||
}
|
||||
|
||||
type sample_function: record {
|
||||
s: string;
|
||||
f: function(str: string): string;
|
||||
};
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local test_sf: sample_function;
|
||||
test_sf$s = "Brogrammers, like bowties, are cool.";
|
||||
|
||||
test_sf$f = triple_string;
|
||||
print test_sf$f(test_sf$s);
|
||||
|
||||
test_sf$f = double_string;
|
||||
print test_sf$f(test_sf$s);
|
||||
|
||||
# Works as expected
|
||||
test_sf$f = function(str: string): string
|
||||
{ return to_upper(str); };
|
||||
print test_sf$f(test_sf$s);
|
||||
|
||||
# Func arg names shouldn't factor in to the type check.
|
||||
test_sf$f = function(s: string): string
|
||||
{ return to_upper(s); };
|
||||
print test_sf$f(test_sf$s);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue