Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in function signature type checking. #1010

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading