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