From 36a3654df438b34b438f4de2725c708000cf69a1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 5 Jun 2024 20:09:17 -0700 Subject: [PATCH] Fix reference types not getting unwrapped for overloads. Bug: issue #970 Test: new test --- compiler/expressions.cpp | 5 +++++ tests/regressions/overload-float-ref.out | 2 ++ tests/regressions/overload-float-ref.sp | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/regressions/overload-float-ref.out create mode 100644 tests/regressions/overload-float-ref.sp diff --git a/compiler/expressions.cpp b/compiler/expressions.cpp index 43104f3a..9082bbe1 100644 --- a/compiler/expressions.cpp +++ b/compiler/expressions.cpp @@ -100,6 +100,11 @@ bool find_userop(SemaContext& sc, int oper, Type* type1, Type* type2, int numpar size_t i; bool savepri, savealt; + if (type1->isReference()) + type1 = type1->inner(); + if (type2 && type2->isReference()) + type2 = type2->inner(); + /* since user-defined operators on untagged operands are forbidden, we have * a quick exit. */ diff --git a/tests/regressions/overload-float-ref.out b/tests/regressions/overload-float-ref.out new file mode 100644 index 00000000..1f06a5d4 --- /dev/null +++ b/tests/regressions/overload-float-ref.out @@ -0,0 +1,2 @@ +143.750000 +10143.750000 diff --git a/tests/regressions/overload-float-ref.sp b/tests/regressions/overload-float-ref.sp new file mode 100644 index 00000000..78678495 --- /dev/null +++ b/tests/regressions/overload-float-ref.sp @@ -0,0 +1,13 @@ +#include + +void test(float& damage) { + printf("%f\n", damage); + int new_damage = 10000; + damage += float(new_damage); + printf("%f\n", damage); +} + +public main() { + float damage = 143.75; + test(damage); +}