Skip to content

Commit

Permalink
Fix bugs in function signature type checking.
Browse files Browse the repository at this point in the history
Bug: issue #992
Test: new test cases
  • Loading branch information
dvander committed Nov 29, 2024
1 parent 71fbc89 commit 72b94a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ static bool funcarg_compare(QualType formal, QualType actual) {
}
}

if (formal_type->isReference() != actual_type->isReference())
return false;

if (!matchtag(formal_type, actual_type, MATCHTAG_SILENT | MATCHTAG_FUNCARG))
return false;
return true;
Expand Down
29 changes: 29 additions & 0 deletions tests/compile-only/fail-ref-compare-function-signature.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
typedef CallbackCell = function void (any value);
typedef CallbackRef = function void (any &value);

public void OnPluginStart()
{
// 4 tests below does report error in 1.11

CallbackCell badcellany = RefAny; // no error
ReturnFunction(badcellany);

CallbackCell badcellint = RefInt; // no error
ReturnFunction(badcellint);

CallbackRef badrefany = CellAny; // no error
ReturnFunction(badrefany);

CallbackRef badrefint = CellInt; // error
ReturnFunction(badrefint);
}

void CellAny(any value) {}
void CellInt(int value) {}
void RefAny(any &value) {}
void RefInt(int &value) {}

Function ReturnFunction(Function func)
{
return func;
}
4 changes: 4 additions & 0 deletions tests/compile-only/fail-ref-compare-function-signature.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(8) : error 100: function prototypes do not match
(11) : error 100: function prototypes do not match
(14) : error 100: function prototypes do not match
(17) : error 100: function prototypes do not match

0 comments on commit 72b94a9

Please sign in to comment.