@@ -335,18 +335,21 @@ class AbstractFunction {
335
335
PolymorphicEffectKind RethrowsKind = PolymorphicEffectKind::None;
336
336
PolymorphicEffectKind ReasyncKind = PolymorphicEffectKind::None;
337
337
SubstitutionMap Substitutions;
338
+ bool AppliedSelf = false ;
338
339
339
340
public:
340
341
explicit AbstractFunction (Kind kind, Expr *fn)
341
342
: TheKind(kind) {
342
343
TheExpr = fn;
343
344
}
344
345
345
- explicit AbstractFunction (AbstractFunctionDecl *fn, SubstitutionMap subs)
346
+ explicit AbstractFunction (AbstractFunctionDecl *fn, SubstitutionMap subs,
347
+ bool appliedSelf)
346
348
: TheKind(Kind::Function),
347
349
RethrowsKind(fn->getPolymorphicEffectKind (EffectKind::Throws)),
348
350
ReasyncKind(fn->getPolymorphicEffectKind (EffectKind::Async)),
349
- Substitutions(subs) {
351
+ Substitutions(subs),
352
+ AppliedSelf(appliedSelf) {
350
353
TheFunction = fn;
351
354
}
352
355
@@ -377,7 +380,7 @@ class AbstractFunction {
377
380
case Kind::Opaque: return getOpaqueFunction ()->getType ();
378
381
case Kind::Function: {
379
382
auto *AFD = getFunction ();
380
- if (AFD->hasImplicitSelfDecl ())
383
+ if (AFD->hasImplicitSelfDecl () && AppliedSelf )
381
384
return AFD->getMethodInterfaceType ();
382
385
return AFD->getInterfaceType ();
383
386
}
@@ -398,6 +401,11 @@ class AbstractFunction {
398
401
.getParameterType ();
399
402
400
403
case Kind::Function: {
404
+ if (getFunction ()->hasImplicitSelfDecl () && !AppliedSelf) {
405
+ assert (substIndex == 0 );
406
+ return getFunction ()->getImplicitSelfDecl ()->getInterfaceType ();
407
+ }
408
+
401
409
auto *params = getFunction ()->getParameters ();
402
410
auto origIndex = params->getOrigParamIndex (getSubstitutions (), substIndex);
403
411
return params->get (origIndex)->getInterfaceType ();
@@ -435,10 +443,13 @@ class AbstractFunction {
435
443
static AbstractFunction getAppliedFn (ApplyExpr *apply) {
436
444
Expr *fn = apply->getFn ()->getValueProvidingExpr ();
437
445
438
- if (auto *selfCall = dyn_cast<SelfApplyExpr>(fn))
446
+ bool appliedSelf = false ;
447
+ if (auto *selfCall = dyn_cast<SelfApplyExpr>(fn)) {
439
448
fn = selfCall->getFn ()->getValueProvidingExpr ();
449
+ appliedSelf = true ;
450
+ }
440
451
441
- return decomposeFunction (fn);
452
+ return decomposeFunction (fn, appliedSelf );
442
453
}
443
454
444
455
bool isPreconcurrency () const {
@@ -457,7 +468,7 @@ class AbstractFunction {
457
468
}
458
469
}
459
470
460
- static AbstractFunction decomposeFunction (Expr *fn) {
471
+ static AbstractFunction decomposeFunction (Expr *fn, bool appliedSelf ) {
461
472
assert (fn->getValueProvidingExpr () == fn);
462
473
463
474
while (true ) {
@@ -493,14 +504,16 @@ class AbstractFunction {
493
504
// Constructor delegation.
494
505
if (auto otherCtorDeclRef = dyn_cast<OtherConstructorDeclRefExpr>(fn)) {
495
506
return AbstractFunction (otherCtorDeclRef->getDecl (),
496
- otherCtorDeclRef->getDeclRef ().getSubstitutions ());
507
+ otherCtorDeclRef->getDeclRef ().getSubstitutions (),
508
+ appliedSelf);
497
509
}
498
510
499
511
// Normal function references.
500
512
if (auto DRE = dyn_cast<DeclRefExpr>(fn)) {
501
513
ValueDecl *decl = DRE->getDecl ();
502
514
if (auto fn = dyn_cast<AbstractFunctionDecl>(decl)) {
503
- return AbstractFunction (fn, DRE->getDeclRef ().getSubstitutions ());
515
+ return AbstractFunction (fn, DRE->getDeclRef ().getSubstitutions (),
516
+ appliedSelf);
504
517
} else if (auto param = dyn_cast<ParamDecl>(decl)) {
505
518
SubstitutionMap subs;
506
519
if (auto genericEnv = param->getDeclContext ()->getGenericEnvironmentOfContext ())
@@ -2541,7 +2554,8 @@ class ApplyClassifier {
2541
2554
2542
2555
// Decompose the function reference, then consider the type
2543
2556
// of the decomposed function.
2544
- AbstractFunction fn = AbstractFunction::decomposeFunction (arg);
2557
+ AbstractFunction fn = AbstractFunction::decomposeFunction (
2558
+ arg, /* appliedSelf=*/ false );
2545
2559
2546
2560
// If it doesn't have function type, we must have invalid code.
2547
2561
Type argType = fn.getType ();
0 commit comments