@@ -2266,7 +2266,6 @@ namespace Slang
2266
2266
2267
2267
// Look at the base expression for the call, and figure out how to invoke it.
2268
2268
auto funcExpr = expr->functionExpr ;
2269
- auto funcExprType = funcExpr->type ;
2270
2269
2271
2270
// If we are trying to apply an erroneous expression, then just bail out now.
2272
2271
if (IsErrorExpr (funcExpr))
@@ -2295,25 +2294,6 @@ namespace Slang
2295
2294
for (auto & arg : expr->arguments )
2296
2295
{
2297
2296
arg = maybeOpenRef (arg);
2298
- }
2299
-
2300
- auto funcType = as<FuncType>(funcExprType);
2301
- for (Index i = 0 ; i < expr->arguments .getCount (); i++)
2302
- {
2303
- auto & arg = expr->arguments [i];
2304
- if (funcType && i < funcType->getParamCount ())
2305
- {
2306
- switch (funcType->getParamDirection (i))
2307
- {
2308
- case kParameterDirection_Out :
2309
- case kParameterDirection_InOut :
2310
- case kParameterDirection_Ref :
2311
- case kParameterDirection_ConstRef :
2312
- continue ;
2313
- default :
2314
- break ;
2315
- }
2316
- }
2317
2297
arg = maybeOpenExistential (arg);
2318
2298
}
2319
2299
@@ -2443,6 +2423,45 @@ namespace Slang
2443
2423
// the user the most help we can.
2444
2424
if (shouldAddToCache)
2445
2425
typeCheckingCache->resolvedOperatorOverloadCache [key] = *context.bestCandidate ;
2426
+
2427
+ // Now that we have resolved the overload candidate, we need to undo an `openExistential`
2428
+ // operation that was applied to `out` arguments.
2429
+ //
2430
+ auto funcType = context.bestCandidate ->funcType ;
2431
+ ShortList<ParameterDirection> paramDirections;
2432
+ if (funcType)
2433
+ {
2434
+ for (Index i = 0 ; i < funcType->getParamCount (); i++)
2435
+ {
2436
+ paramDirections.add (funcType->getParamDirection (i));
2437
+ }
2438
+ }
2439
+ else if (auto callableDeclRef = context.bestCandidate ->item .declRef .as <CallableDecl>())
2440
+ {
2441
+ for (auto param : callableDeclRef.getDecl ()->getParameters ())
2442
+ {
2443
+ paramDirections.add (getParameterDirection (param));
2444
+ }
2445
+ }
2446
+ for (Index i = 0 ; i < expr->arguments .getCount (); i++)
2447
+ {
2448
+ auto & arg = expr->arguments [i];
2449
+ if (i < paramDirections.getCount ())
2450
+ {
2451
+ switch (paramDirections[i])
2452
+ {
2453
+ case kParameterDirection_Out :
2454
+ case kParameterDirection_InOut :
2455
+ case kParameterDirection_Ref :
2456
+ case kParameterDirection_ConstRef :
2457
+ break ;
2458
+ default :
2459
+ continue ;
2460
+ }
2461
+ }
2462
+ if (auto extractExistentialExpr = as<ExtractExistentialValueExpr>(arg))
2463
+ arg = extractExistentialExpr->originalExpr ;
2464
+ }
2446
2465
return CompleteOverloadCandidate (context, *context.bestCandidate );
2447
2466
}
2448
2467
@@ -2475,7 +2494,7 @@ namespace Slang
2475
2494
2476
2495
// Nothing at all was found that we could even consider invoking.
2477
2496
// In all other cases, this is an error.
2478
- getSink ()->diagnose (expr->functionExpr , Diagnostics::expectedFunction, funcExprType );
2497
+ getSink ()->diagnose (expr->functionExpr , Diagnostics::expectedFunction, funcExpr-> type );
2479
2498
expr->type = QualType (m_astBuilder->getErrorType ());
2480
2499
return expr;
2481
2500
}
0 commit comments