diff options
| author | Darren Wihandi <65404740+fairywreath@users.noreply.github.com> | 2025-01-28 21:24:35 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-29 02:24:35 +0000 |
| commit | cf66563cfdcff9b7d76017e5b73319705ccdb735 (patch) | |
| tree | 41c8a5d3706a912049a8c491fd2e7d593d4aa450 /source/slang/slang-check-decl.cpp | |
| parent | 1f99c2086cab3a259c786373ba8d5608e0e1f430 (diff) | |
Fix exact-match witness synthesis for static functions (#6204)
* fix non-static methods when trying to synthesize method requirement witness
* add tests
* update test
* improve test
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 33319ca8f..d0c3e8d96 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -4621,6 +4621,25 @@ static bool matchParamDirection(ParameterDirection implDir, ParameterDirection r return false; } +static void removeNonStaticLookupItems(LookupResult& lookupResult) +{ + List<LookupResultItem> newItems; + for (auto item : lookupResult) + { + if (item.declRef.getDecl()->hasModifier<HLSLStaticModifier>()) + { + newItems.add(item); + } + } + + lookupResult.items = newItems; + lookupResult.item = LookupResultItem(); + if (lookupResult.items.getCount() > 0) + { + lookupResult.item = lookupResult.items[0]; + } +} + bool SemanticsVisitor::trySynthesizeMethodRequirementWitness( ConformanceCheckingContext* context, LookupResult const& lookupResult, @@ -4724,6 +4743,12 @@ bool SemanticsVisitor::trySynthesizeMethodRequirementWitness( baseOverloadedExpr->lookupResult2 = lookupResult; } + // Non-static methods cannot implement static methods, remove them. + if (requiredMemberDeclRef.getDecl()->hasModifier<HLSLStaticModifier>()) + { + removeNonStaticLookupItems(baseOverloadedExpr->lookupResult2); + } + // If `synThis` is non-null, then we will use it as the base of // the overloaded expression, so that we have an overloaded // member reference, and not just an overloaded reference to some |
