summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-overload.cpp
diff options
context:
space:
mode:
authorJulius Ikkala <julius.ikkala@gmail.com>2025-04-11 23:19:04 +0300
committerGitHub <noreply@github.com>2025-04-11 20:19:04 +0000
commit88a180ba0aa57b2d0fb4956005db2ea73dc73420 (patch)
tree4569f44c7549e941ea63ec71795442c7e3778b42 /source/slang/slang-check-overload.cpp
parent1c719a998cf251c27a92975832ec4c1f37d63597 (diff)
Add a more specific diagnostic message when passing concrete value to interface-typed output parameter (#6788)
* More specific diagnostic for invalid concrete-to-interface arg coercion * Add test for the new error message * Fix typo in expected test result
Diffstat (limited to 'source/slang/slang-check-overload.cpp')
-rw-r--r--source/slang/slang-check-overload.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 21fc21df6..b818c9e06 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -711,7 +711,35 @@ bool SemanticsVisitor::TryCheckOverloadCandidateTypes(
}
else
{
- arg.argExpr = coerce(CoercionSite::Argument, paramType, arg.argExpr);
+ Expr* coercedExpr = coerce(CoercionSite::Argument, paramType, arg.argExpr);
+
+ // Check if concrete-to-interface coercion caused loss of l-valueness.
+ if (coercedExpr && !coercedExpr->type.isLeftValue && paramType.isLeftValue &&
+ !isInterfaceType(arg.type) && isInterfaceType(paramType.type))
+ {
+ if (context.mode != OverloadResolveContext::Mode::JustTrying)
+ {
+ String name;
+ if (candidate.flavor == OverloadCandidate::Flavor::Func)
+ {
+ auto decl = getParameters(
+ m_astBuilder,
+ candidate.item.declRef.as<CallableDecl>())[paramIndex];
+ name = getText(decl.getName());
+ }
+ else
+ name.append(paramIndex, 10);
+
+ getSink()->diagnose(
+ context.loc,
+ Diagnostics::concreteArgumentToOutputInterface,
+ name,
+ arg.type,
+ paramType.type);
+ }
+ return {nullptr, nullptr};
+ }
+ arg.argExpr = coercedExpr;
}
return arg;
};