Skip to content
Closed
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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ TESTSUITE ( and-or-not-synonyms aastep arithmetic array array-derivs array-range
operator-overloading
oslc-comma oslc-D
oslc-err-arrayindex oslc-err-closuremul oslc-err-field
oslc-err-format oslc-err-funcredef oslc-err-intoverflow
oslc-err-noreturn oslc-err-notfunc
oslc-err-format oslc-err-funcoverload oslc-err-funcredef
oslc-err-intoverflow oslc-err-noreturn oslc-err-notfunc
oslc-err-outputparamvararray oslc-err-paramdefault
oslc-err-struct-array-init oslc-err-struct-ctr
oslc-err-struct-dup
Expand Down
15 changes: 10 additions & 5 deletions src/liboslcomp/typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,26 +1017,26 @@ class CandidateFunctions {
++fargs;
case '\0':
if (fargs < m_nargs)
return 0;
return kNoMatch;
break;

default:
// TODO: Scoring default function arguments would go here
// Curently an unused formal argument, so no match at all.
return 0;
return kNoMatch;
}
ASSERT (*formals == 0);

int highscore = m_candidates.empty() ? 0 : m_candidates.front().ascore;
if (argscore < highscore)
return 0;
return kNoMatch;


if (argscore == highscore) {
// Check for duplicate declarations
for (auto& candidate : m_candidates) {
if (candidate.sym->argcodes() == func->argcodes())
return 0;
return kNoMatch;
}
} else // clear any prior ambiguous matches
m_candidates.clear();
Expand Down Expand Up @@ -1392,6 +1392,9 @@ ASTfunction_call::typecheck (TypeSpec expected)
return typecheck_struct_constructor ();
}

// Save the current symbol to maybe report an error later.
FunctionSymbol *poly = func();

CandidateFunctions candidates(m_compiler, expected, args(), func());
std::tie(m_sym, m_typespec) = candidates.best(this);

Expand All @@ -1418,8 +1421,10 @@ ASTfunction_call::typecheck (TypeSpec expected)
// message.
candidates.reportError(this, m_name);

for (FunctionSymbol *poly = func(); poly; poly = poly->nextpoly())
while (poly) {
candidates.reportAmbiguity(poly);
poly = poly->nextpoly();
}

return TypeSpec();
}
Expand Down
11 changes: 11 additions & 0 deletions testsuite/oslc-err-funcoverload/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test.osl:8: error: No matching function call to 'funca ()'
test.osl:3 candidate function:
void funca (int, int)
test.osl:2 candidate function:
void funca (int)
test.osl:9: error: No matching function call to 'funca (int, int, int)'
test.osl:3 candidate function:
void funca (int, int)
test.osl:2 candidate function:
void funca (int)
FAILED test.osl
5 changes: 5 additions & 0 deletions testsuite/oslc-err-funcoverload/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python

# command = oslc("test.osl")
# don't even need that -- it's automatic
failureok = 1 # this test is expected to have oslc errors
11 changes: 11 additions & 0 deletions testsuite/oslc-err-funcoverload/test.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

void funca(int a) {}
void funca(int a, int b) {}


shader test()
{
funca();
funca(1,2,3);
}