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

Dyno: fix disambiguation between fully-generic vararg and less generic non-vararg. #26456

Merged
merged 2 commits into from
Jan 6, 2025
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
7 changes: 7 additions & 0 deletions frontend/lib/resolution/disambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,13 @@ static bool isFormalInstantiatedAny(const DisambiguationCandidate& candidate,

if (qt.type() && qt.type()->isAnyType())
return true;

if (initial->untyped()->formalIsVarArgs(formalIdx) &&
qt.type() && qt.type()->isTupleType()) {
auto tt = qt.type()->toTupleType();
CHPL_ASSERT(tt && tt->isStarTuple());
return tt->starType().type() && tt->starType().type()->isAnyType();
}
}

return false;
Expand Down
19 changes: 19 additions & 0 deletions frontend/test/resolution/testVarArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,24 @@ var c = fn(y=5.0, "hello", 1, "test", 3.0);

}

// regression test for a bug in which two fucntions (see body of the test)
// are incorrectly considered ambiguous. The vararg-based function is less
// specific than the 'integral'-based function since the latter constraints
// the type more.
static void testGenericInstantiationDisambiguation() {
Context* context = buildStdContext();
auto program =
R"""(
proc foo(x...) do return 1.0;
proc foo(x: integral) do return 1;

var x = foo(10);
)""";

auto qt = resolveTypeOfX(context, program);
CHPL_ASSERT(qt->isIntType());
}

//
// TODO: test where-clauses:
//
Expand Down Expand Up @@ -864,6 +882,7 @@ int main(int argc, char** argv) {
testConcrete();
testCount();
testAlignment();
testGenericInstantiationDisambiguation();

printf("\nAll tests passed successfully.\n");

Expand Down
Loading