diff options
| author | Yong He <yonghe@outlook.com> | 2024-09-04 13:26:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-04 13:26:16 -0700 |
| commit | 599dae52e85d2a86bf3cae1ebd0883fedf44a76e (patch) | |
| tree | f9c807080bfdc9580fea345c45550310b7ac6c9d /source/slang/slang-check-overload.cpp | |
| parent | ddd29057e48a5b309726750e3daf78bfd073038e (diff) | |
Open existential on arguments after overload resolution. (#4982)
* Open existential on arguments after overload resolution.
* Fix.
* Update source/slang/slang-check-overload.cpp
Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
---------
Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-check-overload.cpp')
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 0e01eeed2..7318fa390 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -2266,7 +2266,6 @@ namespace Slang // Look at the base expression for the call, and figure out how to invoke it. auto funcExpr = expr->functionExpr; - auto funcExprType = funcExpr->type; // If we are trying to apply an erroneous expression, then just bail out now. if(IsErrorExpr(funcExpr)) @@ -2295,25 +2294,6 @@ namespace Slang for (auto& arg : expr->arguments) { arg = maybeOpenRef(arg); - } - - auto funcType = as<FuncType>(funcExprType); - for (Index i = 0; i < expr->arguments.getCount(); i++) - { - auto& arg = expr->arguments[i]; - if (funcType && i < funcType->getParamCount()) - { - switch (funcType->getParamDirection(i)) - { - case kParameterDirection_Out: - case kParameterDirection_InOut: - case kParameterDirection_Ref: - case kParameterDirection_ConstRef: - continue; - default: - break; - } - } arg = maybeOpenExistential(arg); } @@ -2443,6 +2423,45 @@ namespace Slang // the user the most help we can. if (shouldAddToCache) typeCheckingCache->resolvedOperatorOverloadCache[key] = *context.bestCandidate; + + // Now that we have resolved the overload candidate, we need to undo an `openExistential` + // operation that was applied to `out` arguments. + // + auto funcType = context.bestCandidate->funcType; + ShortList<ParameterDirection> paramDirections; + if (funcType) + { + for (Index i = 0; i < funcType->getParamCount(); i++) + { + paramDirections.add(funcType->getParamDirection(i)); + } + } + else if (auto callableDeclRef = context.bestCandidate->item.declRef.as<CallableDecl>()) + { + for (auto param : callableDeclRef.getDecl()->getParameters()) + { + paramDirections.add(getParameterDirection(param)); + } + } + for (Index i = 0; i < expr->arguments.getCount(); i++) + { + auto& arg = expr->arguments[i]; + if (i < paramDirections.getCount()) + { + switch (paramDirections[i]) + { + case kParameterDirection_Out: + case kParameterDirection_InOut: + case kParameterDirection_Ref: + case kParameterDirection_ConstRef: + break; + default: + continue; + } + } + if (auto extractExistentialExpr = as<ExtractExistentialValueExpr>(arg)) + arg = extractExistentialExpr->originalExpr; + } return CompleteOverloadCandidate(context, *context.bestCandidate); } @@ -2475,7 +2494,7 @@ namespace Slang // Nothing at all was found that we could even consider invoking. // In all other cases, this is an error. - getSink()->diagnose(expr->functionExpr, Diagnostics::expectedFunction, funcExprType); + getSink()->diagnose(expr->functionExpr, Diagnostics::expectedFunction, funcExpr->type); expr->type = QualType(m_astBuilder->getErrorType()); return expr; } |
