Skip to content

Commit

Permalink
Reject equivalent functions.
Browse files Browse the repository at this point in the history
Fixes #1982
  • Loading branch information
evantypanski committed Mar 7, 2025
1 parent 4170aff commit 8311f0b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hilti/toolchain/src/ast/types/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ bool type::Function::isResolved(node::CycleDetector* cd) const {
}

bool type::isValidOverload(Function* f1, Function* f2) {
if ( f1->flavor() != function::Flavor::Hook && areEquivalent(f1, f2) )
return false;

const auto& params1 = f1->parameters();
const auto& params2 = f2->parameters();

Expand Down
4 changes: 4 additions & 0 deletions tests/Baseline/hilti.validation.duplicate-6/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] <...>/duplicate.hlt:6:1-6:33: 'fail1' is not a valid overload; previous definition in <...>/duplicate.hlt:5:1-5:33
[error] <...>/duplicate.hlt:9:1-9:72: 'fail2' is not a valid overload; previous definition in <...>/duplicate.hlt:8:1-8:60
[error] hiltic: aborting after errors
13 changes: 13 additions & 0 deletions tests/hilti/validation/duplicate.hlt
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,16 @@ function uint<16> fun(uint<8> a, uint<8> b = uint8(0)) {
hilti::print(fun(uint8(1)));

}

# @TEST-START-NEXT

module Foo {

# Equivalent functions signatures should not be allowed.
function void fail1() { return; }
function void fail1() { return; }

function string fail2(uint<8> x, string y) { return "hi!"; }
function string fail2(uint<8> different, string names) { return "hi!"; }

}

0 comments on commit 8311f0b

Please sign in to comment.