Skip to content

Commit

Permalink
Fix reference types not getting unwrapped for overloads.
Browse files Browse the repository at this point in the history
Bug: issue #970
Test: new test
  • Loading branch information
dvander committed Jun 6, 2024
1 parent 79a619c commit 2213b8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/regressions/overload-float-ref.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
143.750000
10143.750000
13 changes: 13 additions & 0 deletions tests/regressions/overload-float-ref.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <shell>

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);
}

0 comments on commit 2213b8e

Please sign in to comment.