From 050860db74a82427e8ae2460836eb691d889e232 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 29 Nov 2024 16:44:47 -0500 Subject: [PATCH] Fix bugs in function signature type checking. Bug: issue #992 Test: new test cases --- compiler/expressions.cpp | 3 ++ .../fail-ref-compare-function-signature.sp | 29 +++++++++++++++++++ .../fail-ref-compare-function-signature.txt | 4 +++ 3 files changed, 36 insertions(+) create mode 100644 tests/compile-only/fail-ref-compare-function-signature.sp create mode 100644 tests/compile-only/fail-ref-compare-function-signature.txt diff --git a/compiler/expressions.cpp b/compiler/expressions.cpp index 9082bbe1..df478f35 100644 --- a/compiler/expressions.cpp +++ b/compiler/expressions.cpp @@ -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; diff --git a/tests/compile-only/fail-ref-compare-function-signature.sp b/tests/compile-only/fail-ref-compare-function-signature.sp new file mode 100644 index 00000000..0cfd472f --- /dev/null +++ b/tests/compile-only/fail-ref-compare-function-signature.sp @@ -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; +} diff --git a/tests/compile-only/fail-ref-compare-function-signature.txt b/tests/compile-only/fail-ref-compare-function-signature.txt new file mode 100644 index 00000000..77b928a9 --- /dev/null +++ b/tests/compile-only/fail-ref-compare-function-signature.txt @@ -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