summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-overload.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-03 15:20:23 -0700
committerGitHub <noreply@github.com>2025-07-03 22:20:23 +0000
commitb4fc380af5e390ca11892f9e657e653f6869c21b (patch)
tree9072841ed14a190cce0790ced27b283f85d1fc4f /source/slang/slang-check-overload.cpp
parent551d0c365571a2e36505851f6a713464662c5fea (diff)
Language Server Enhancements (#7604)
* Language Server: auto-select the best candidate in signature help. * Fix constructor call highlighting + goto definition. * Add test. * format code * Improve ctor signature help. * Add tests. * Fix decl path printing for extension children. * Allow goto definition to show core module source. * c++ compile fix. --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-check-overload.cpp')
-rw-r--r--source/slang/slang-check-overload.cpp35
1 files changed, 25 insertions, 10 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 6c0a7f184..41aba2674 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -2249,6 +2249,24 @@ DeclRef<Decl> SemanticsVisitor::inferGenericArguments(
return trySolveConstraintSystem(&constraints, genericDeclRef, knownGenericArgs, outBaseCost);
}
+LookupResult SemanticsVisitor::lookupConstructorsInType(Type* type, Scope* sourceScope)
+{
+ // Look up all the initializers on `type` by looking up
+ // its members named `$init`. All `__init` declarations are stored
+ // with the name `$init` internally to avoid potential conflicts
+ // if a user decided to name a field/method `__init`.
+ LookupOptions options =
+ LookupOptions(uint8_t(LookupOptions::IgnoreInheritance) | uint8_t(LookupOptions::NoDeref));
+ return lookUpMember(
+ m_astBuilder,
+ this,
+ getName("$init"),
+ type,
+ sourceScope,
+ LookupMask::Default,
+ options);
+}
+
void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveContext& context)
{
// The code being checked is trying to apply `type` like a function.
@@ -2272,16 +2290,7 @@ void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveCont
// from a value of the same type. There is no need in Slang for
// "copy constructors" but the core module currently has to define
// some just to make code that does, e.g., `float(1.0f)` work.)
- LookupOptions options =
- LookupOptions(uint8_t(LookupOptions::IgnoreInheritance) | uint8_t(LookupOptions::NoDeref));
- LookupResult initializers = lookUpMember(
- m_astBuilder,
- this,
- getName("$init"),
- type,
- context.sourceScope,
- LookupMask::Default,
- options);
+ LookupResult initializers = lookupConstructorsInType(type, context.sourceScope);
AddOverloadCandidates(initializers, context);
}
@@ -2702,6 +2711,12 @@ Expr* SemanticsVisitor::ResolveInvoke(InvokeExpr* expr)
expr->arguments[0],
&tempSink,
&conversionCost);
+ if (auto resultInvokeExpr = as<InvokeExpr>(resultExpr))
+ {
+ resultInvokeExpr->originalFunctionExpr = expr->functionExpr;
+ resultInvokeExpr->argumentDelimeterLocs = expr->argumentDelimeterLocs;
+ resultInvokeExpr->loc = expr->loc;
+ }
if (coerceResult)
return resultExpr;
typeOverloadChecked = true;