@@ -1658,33 +1658,14 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1658
1658
1659
1659
// Figure out the instance type used for the base.
1660
1660
Type baseRValueTy = baseTy->getRValueType ();
1661
+ auto baseObjTy = baseRValueTy->getMetatypeInstanceType ();
1661
1662
1662
1663
// If the base is a module type, just use the type of the decl.
1663
- if (baseRValueTy ->is <ModuleType>()) {
1664
+ if (baseObjTy ->is <ModuleType>()) {
1664
1665
return getTypeOfReference (value, functionRefInfo, locator, useDC,
1665
1666
preparedOverload);
1666
1667
}
1667
1668
1668
- // Check to see if the self parameter is applied, in which case we'll want to
1669
- // strip it off later.
1670
- auto hasAppliedSelf = doesMemberRefApplyCurriedSelf (baseRValueTy, value);
1671
-
1672
- auto baseObjTy = baseRValueTy->getMetatypeInstanceType ();
1673
- FunctionType::Param baseObjParam (baseObjTy);
1674
-
1675
- // Indicates whether this is a valid reference to a static member on a
1676
- // protocol metatype. Such a reference is only valid if performed through
1677
- // leading dot syntax e.g. `foo(.bar)` where implicit base is a protocol
1678
- // metatype and `bar` is static member declared in a protocol or its
1679
- // extension.
1680
- bool isStaticMemberRefOnProtocol = false ;
1681
- if (baseObjTy->isExistentialType () && value->isStatic () &&
1682
- locator->isLastElement <LocatorPathElt::UnresolvedMember>()) {
1683
- assert (baseRValueTy->is <MetatypeType>() &&
1684
- " Assumed base of unresolved member access must be a metatype" );
1685
- isStaticMemberRefOnProtocol = true ;
1686
- }
1687
-
1688
1669
if (auto *typeDecl = dyn_cast<TypeDecl>(value)) {
1689
1670
assert (!isa<ModuleDecl>(typeDecl) && " Nested module?" );
1690
1671
@@ -1711,6 +1692,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1711
1692
memberTy = MetatypeType::get (memberTy);
1712
1693
}
1713
1694
1695
+ FunctionType::Param baseObjParam (baseObjTy);
1714
1696
auto openedType = FunctionType::get ({baseObjParam}, memberTy);
1715
1697
return { openedType, openedType, memberTy, memberTy, Type () };
1716
1698
}
@@ -1745,6 +1727,10 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1745
1727
replacements = _replacements;
1746
1728
}
1747
1729
1730
+ // Check to see if the self parameter is applied, in which case we'll want to
1731
+ // strip it off later.
1732
+ auto hasAppliedSelf = doesMemberRefApplyCurriedSelf (baseRValueTy, value);
1733
+
1748
1734
Type thrownErrorType;
1749
1735
if (isa<AbstractFunctionDecl>(value) ||
1750
1736
isa<EnumElementDecl>(value) ||
@@ -1842,30 +1828,42 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
1842
1828
1843
1829
openedType = openedType->removeArgumentLabels (numRemovedArgumentLabels);
1844
1830
1845
- // If we are looking at a member of an existential, open the existential.
1846
1831
Type baseOpenedTy = baseObjTy;
1847
1832
1848
- if (isStaticMemberRefOnProtocol) {
1849
- // In diagnostic mode, let's not try to replace base type
1850
- // if there is already a known issue associated with this
1851
- // reference e.g. it might be incorrect initializer call
1852
- // or result type is invalid.
1853
- if (!(shouldAttemptFixes () && hasFixFor (getConstraintLocator (locator)))) {
1854
- if (auto concreteSelf =
1855
- getConcreteReplacementForProtocolSelfType (value)) {
1856
- // Concrete type replacing `Self` could be generic, so we need
1857
- // to make sure that it's opened before use.
1858
- baseOpenedTy = openType (concreteSelf, replacements, locator,
1859
- preparedOverload);
1860
- baseObjTy = baseOpenedTy;
1833
+ // If we are looking at a member of an existential, open the existential.
1834
+ if (baseObjTy->isExistentialType ()) {
1835
+ if (value->isStatic () &&
1836
+ locator->isLastElement <LocatorPathElt::UnresolvedMember>()) {
1837
+ // Indicates whether this is a valid reference to a static member on a
1838
+ // protocol metatype. Such a reference is only valid if performed through
1839
+ // leading dot syntax e.g. `foo(.bar)` where implicit base is a protocol
1840
+ // metatype and `bar` is static member declared in a protocol or its
1841
+ // extension.
1842
+ assert (baseRValueTy->is <MetatypeType>() &&
1843
+ " Assumed base of unresolved member access must be a metatype" );
1844
+
1845
+ // In diagnostic mode, let's not try to replace base type
1846
+ // if there is already a known issue associated with this
1847
+ // reference e.g. it might be incorrect initializer call
1848
+ // or result type is invalid.
1849
+ if (!(shouldAttemptFixes () && hasFixFor (getConstraintLocator (locator)))) {
1850
+ if (auto concreteSelf =
1851
+ getConcreteReplacementForProtocolSelfType (value)) {
1852
+ // Concrete type replacing `Self` could be generic, so we need
1853
+ // to make sure that it's opened before use.
1854
+ baseOpenedTy = openType (concreteSelf, replacements, locator,
1855
+ preparedOverload);
1856
+ baseObjTy = baseOpenedTy;
1857
+ }
1861
1858
}
1859
+ } else {
1860
+ // Open the existential.
1861
+ auto openedArchetype =
1862
+ ExistentialArchetypeType::get (baseObjTy->getCanonicalType ());
1863
+ recordOpenedExistentialType (getConstraintLocator (locator), openedArchetype,
1864
+ preparedOverload);
1865
+ baseOpenedTy = openedArchetype;
1862
1866
}
1863
- } else if (baseObjTy->isExistentialType ()) {
1864
- auto openedArchetype =
1865
- ExistentialArchetypeType::get (baseObjTy->getCanonicalType ());
1866
- recordOpenedExistentialType (getConstraintLocator (locator), openedArchetype,
1867
- preparedOverload);
1868
- baseOpenedTy = openedArchetype;
1869
1867
}
1870
1868
1871
1869
// Constrain the 'self' object type.
0 commit comments