@@ -1633,6 +1633,49 @@ namespace {
16331633 return outerThunk;
16341634 }
16351635
1636+ Expr *buildDynamicMemberRef (Expr *base, Type baseTy,
1637+ SourceLoc dotLoc,
1638+ ConcreteDeclRef memberRef,
1639+ Type openedType,
1640+ Type adjustedOpenedType,
1641+ DeclNameLoc memberLoc,
1642+ ConstraintLocatorBuilder locator,
1643+ ConstraintLocatorBuilder memberLocator,
1644+ bool openedExistential,
1645+ bool Implicit) {
1646+ base = cs.coerceToRValue (base);
1647+ Expr *ref = new (ctx) DynamicMemberRefExpr (base, dotLoc, memberRef,
1648+ memberLoc);
1649+ ref->setImplicit (Implicit);
1650+ // FIXME: FunctionRefInfo
1651+
1652+ // Compute the type of the reference.
1653+ auto computeRefType = [&](Type refType) {
1654+ // If the base was an opened existential, erase the opened
1655+ // existential.
1656+ if (openedExistential) {
1657+ refType = typeEraseOpenedArchetypesFromEnvironment (
1658+ refType, baseTy->castTo <ExistentialArchetypeType>()->getGenericEnvironment ());
1659+ }
1660+
1661+ return refType;
1662+ };
1663+
1664+ Type refType = computeRefType (openedType);
1665+ cs.setType (ref, refType);
1666+
1667+ // Adjust the declaration reference type, if required.
1668+ ref = adjustTypeForDeclReference (
1669+ ref, openedType, adjustedOpenedType, locator, computeRefType);
1670+
1671+ closeExistentials (ref, locator, /* force=*/ openedExistential);
1672+
1673+ // We also need to handle the implicitly unwrap of the result
1674+ // of the called function if that's the type checking solution
1675+ // we ended up with.
1676+ return forceUnwrapIfExpected (ref, memberLocator);
1677+ }
1678+
16361679 // / Build a new member reference with the given base and member.
16371680 Expr *buildMemberRef (Expr *base, SourceLoc dotLoc,
16381681 SelectedOverload overload, DeclNameLoc memberLoc,
@@ -1857,37 +1900,10 @@ namespace {
18571900 // Handle dynamic references.
18581901 if (!needsCurryThunk &&
18591902 (isDynamic || member->getAttrs ().hasAttribute <OptionalAttr>())) {
1860- base = cs.coerceToRValue (base);
1861- Expr *ref = new (ctx) DynamicMemberRefExpr (base, dotLoc, memberRef,
1862- memberLoc);
1863- ref->setImplicit (Implicit);
1864- // FIXME: FunctionRefInfo
1865-
1866- // Compute the type of the reference.
1867- auto computeRefType = [&](Type refType) {
1868- // If the base was an opened existential, erase the opened
1869- // existential.
1870- if (openedExistential) {
1871- refType = typeEraseOpenedArchetypesFromEnvironment (
1872- refType, baseTy->castTo <ExistentialArchetypeType>()->getGenericEnvironment ());
1873- }
1874-
1875- return refType;
1876- };
1877-
1878- Type refType = computeRefType (openedType);
1879- cs.setType (ref, refType);
1880-
1881- // Adjust the declaration reference type, if required.
1882- ref = adjustTypeForDeclReference (
1883- ref, openedType, adjustedOpenedType, locator, computeRefType);
1884-
1885- closeExistentials (ref, locator, /* force=*/ openedExistential);
1886-
1887- // We also need to handle the implicitly unwrap of the result
1888- // of the called function if that's the type checking solution
1889- // we ended up with.
1890- return forceUnwrapIfExpected (ref, memberLocator);
1903+ return buildDynamicMemberRef (base, baseTy, dotLoc, memberRef,
1904+ openedType, adjustedOpenedType,
1905+ memberLoc, locator, memberLocator,
1906+ openedExistential, Implicit);
18911907 }
18921908
18931909 // For properties, build member references.
0 commit comments