From 1f7b9aac7476365d12f1ff16044c7078e68cafd6 Mon Sep 17 00:00:00 2001 From: Frederich Munch Date: Sat, 20 Jan 2018 11:05:51 -0500 Subject: [PATCH 1/2] Fix regression where function overload candidates might not be reported and add test. --- CMakeLists.txt | 4 ++-- src/liboslcomp/typecheck.cpp | 7 ++++++- testsuite/oslc-err-funcoverload/ref/out.txt | 11 +++++++++++ testsuite/oslc-err-funcoverload/run.py | 5 +++++ testsuite/oslc-err-funcoverload/test.osl | 11 +++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 testsuite/oslc-err-funcoverload/ref/out.txt create mode 100755 testsuite/oslc-err-funcoverload/run.py create mode 100644 testsuite/oslc-err-funcoverload/test.osl diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b391600b..015346214 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/liboslcomp/typecheck.cpp b/src/liboslcomp/typecheck.cpp index fd61a18bc..c9999fc4c 100644 --- a/src/liboslcomp/typecheck.cpp +++ b/src/liboslcomp/typecheck.cpp @@ -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); @@ -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(); } diff --git a/testsuite/oslc-err-funcoverload/ref/out.txt b/testsuite/oslc-err-funcoverload/ref/out.txt new file mode 100644 index 000000000..1ce245436 --- /dev/null +++ b/testsuite/oslc-err-funcoverload/ref/out.txt @@ -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 diff --git a/testsuite/oslc-err-funcoverload/run.py b/testsuite/oslc-err-funcoverload/run.py new file mode 100755 index 000000000..d901e097a --- /dev/null +++ b/testsuite/oslc-err-funcoverload/run.py @@ -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 diff --git a/testsuite/oslc-err-funcoverload/test.osl b/testsuite/oslc-err-funcoverload/test.osl new file mode 100644 index 000000000..a53cfe282 --- /dev/null +++ b/testsuite/oslc-err-funcoverload/test.osl @@ -0,0 +1,11 @@ + +void funca(int a) {} +void funca(int a, int b) {} + + +shader test() +{ + funca(); + funca(1,2,3); +} + From e52b789770cb17f382403689a42eadcb935acc3f Mon Sep 17 00:00:00 2001 From: Frederich Munch Date: Sat, 20 Jan 2018 14:13:57 -0500 Subject: [PATCH 2/2] Use named constant instead of 0 (no functional change). --- src/liboslcomp/typecheck.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liboslcomp/typecheck.cpp b/src/liboslcomp/typecheck.cpp index c9999fc4c..d64b91802 100644 --- a/src/liboslcomp/typecheck.cpp +++ b/src/liboslcomp/typecheck.cpp @@ -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();