@@ -2358,6 +2358,13 @@ ConstraintSystem::getTypeOfMemberReference(
2358
2358
return { openedType, openedType, memberTy, memberTy };
2359
2359
}
2360
2360
2361
+ if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
2362
+ if (value->getInterfaceType ()->is <ErrorType>()) {
2363
+ auto genericErrorTy = ErrorType::get (getASTContext ());
2364
+ return { genericErrorTy, genericErrorTy, genericErrorTy, genericErrorTy };
2365
+ }
2366
+ }
2367
+
2361
2368
// Figure out the declaration context to use when opening this type.
2362
2369
DeclContext *innerDC = value->getInnermostDeclContext ();
2363
2370
DeclContext *outerDC = value->getDeclContext ();
@@ -2366,18 +2373,22 @@ ConstraintSystem::getTypeOfMemberReference(
2366
2373
Type openedType;
2367
2374
OpenedTypeMap localReplacements;
2368
2375
auto &replacements = replacementsPtr ? *replacementsPtr : localReplacements;
2369
- unsigned numRemovedArgumentLabels = getNumRemovedArgumentLabels (
2370
- value, /* isCurriedInstanceReference*/ !hasAppliedSelf, functionRefKind);
2371
2376
2372
- AnyFunctionType *funcType;
2377
+ // If we have a generic signature, open the parameters. We delay opening
2378
+ // requirements to allow contextual types to affect the situation.
2379
+ auto genericSig = innerDC->getGenericSignatureOfContext ();
2380
+ if (genericSig)
2381
+ openGenericParameters (outerDC, genericSig, replacements, locator);
2373
2382
2374
2383
if (isa<AbstractFunctionDecl>(value) || isa<EnumElementDecl>(value)) {
2375
- if (auto ErrorTy = value->getInterfaceType ()->getAs <ErrorType>()) {
2376
- auto genericErrorTy = ErrorType::get (ErrorTy->getASTContext ());
2377
- return { genericErrorTy, genericErrorTy, genericErrorTy, genericErrorTy };
2378
- }
2379
2384
// This is the easy case.
2380
- funcType = value->getInterfaceType ()->castTo <AnyFunctionType>();
2385
+ openedType = value->getInterfaceType ()->castTo <AnyFunctionType>();
2386
+
2387
+ if (auto *genericFn = openedType->getAs <GenericFunctionType>()) {
2388
+ openedType = genericFn->substGenericArgs ([&](Type type) {
2389
+ return openType (type, replacements);
2390
+ });
2391
+ }
2381
2392
} else {
2382
2393
// For a property, build a type (Self) -> PropType.
2383
2394
// For a subscript, build a type (Self) -> (Indices...) -> ElementType.
@@ -2418,29 +2429,21 @@ ConstraintSystem::getTypeOfMemberReference(
2418
2429
!selfTy->hasError ())
2419
2430
selfFlags = selfFlags.withInOut (true );
2420
2431
2421
- // If the storage is generic, add a generic signature.
2432
+ // If the storage is generic, open the self and ref types.
2433
+ if (genericSig) {
2434
+ selfTy = openType (selfTy, replacements);
2435
+ refType = openType (refType, replacements);
2436
+ }
2422
2437
FunctionType::Param selfParam (selfTy, Identifier (), selfFlags);
2438
+
2423
2439
// FIXME: Verify ExtInfo state is correct, not working by accident.
2424
- if (auto sig = innerDC->getGenericSignatureOfContext ()) {
2425
- GenericFunctionType::ExtInfo info;
2426
- funcType = GenericFunctionType::get (sig, {selfParam}, refType, info);
2427
- } else {
2428
- FunctionType::ExtInfo info;
2429
- funcType = FunctionType::get ({selfParam}, refType, info);
2430
- }
2440
+ FunctionType::ExtInfo info;
2441
+ openedType = FunctionType::get ({selfParam}, refType, info);
2431
2442
}
2443
+ assert (!openedType->hasTypeParameter ());
2432
2444
2433
- // While opening member function type, let's delay opening requirements
2434
- // to allow contextual types to affect the situation.
2435
- if (auto *genericFn = funcType->getAs <GenericFunctionType>()) {
2436
- openGenericParameters (outerDC, genericFn->getGenericSignature (),
2437
- replacements, locator);
2438
-
2439
- openedType = genericFn->substGenericArgs (
2440
- [&](Type type) { return openType (type, replacements); });
2441
- } else {
2442
- openedType = funcType;
2443
- }
2445
+ unsigned numRemovedArgumentLabels = getNumRemovedArgumentLabels (
2446
+ value, /* isCurriedInstanceReference*/ !hasAppliedSelf, functionRefKind);
2444
2447
2445
2448
openedType = openedType->removeArgumentLabels (numRemovedArgumentLabels);
2446
2449
@@ -2491,9 +2494,9 @@ ConstraintSystem::getTypeOfMemberReference(
2491
2494
// failing we'll get a generic requirement constraint failure
2492
2495
// if mismatch is related to generic parameters which is much
2493
2496
// easier to diagnose.
2494
- if (auto *genericFn = funcType-> getAs <GenericFunctionType>() ) {
2497
+ if (genericSig ) {
2495
2498
openGenericRequirements (
2496
- outerDC, genericFn-> getGenericSignature () ,
2499
+ outerDC, genericSig ,
2497
2500
/* skipProtocolSelfConstraint=*/ true , locator,
2498
2501
[&](Type type) { return openType (type, replacements); });
2499
2502
}
0 commit comments