@@ -903,11 +903,6 @@ namespace {
903903 bool baseIsInstance) {
904904 ValueDecl *member = choice.getDecl ();
905905
906- // FIXME: We should finish plumbing this through for dynamic
907- // lookup as well.
908- if (choice.getKind () == OverloadChoiceKind::DeclViaDynamic)
909- return false ;
910-
911906 // If we're inside a selector expression, don't build the thunk.
912907 // Were not actually going to emit the member reference, just
913908 // look at the AST.
@@ -921,9 +916,11 @@ namespace {
921916 if (!baseIsInstance && member->isInstanceMember ())
922917 return true ;
923918
924- // Bound optional method references are represented via
925- // DynamicMemberRefExpr instead of a curry thunk.
926- if (member->getAttrs ().hasAttribute <OptionalAttr>())
919+ // Bound member references that are '@objc optional' or found via dynamic
920+ // lookup are always represented via DynamicMemberRefExpr instead of a
921+ // curry thunk.
922+ if (member->getAttrs ().hasAttribute <OptionalAttr>() ||
923+ choice.getKind () == OverloadChoiceKind::DeclViaDynamic)
927924 return false ;
928925
929926 // Figure out how many argument lists we need.
@@ -1590,8 +1587,8 @@ namespace {
15901587 }
15911588
15921589 // Handle dynamic references.
1593- if (isDynamic || ( !needsCurryThunk &&
1594- member->getAttrs ().hasAttribute <OptionalAttr>())) {
1590+ if (!needsCurryThunk &&
1591+ (isDynamic || member->getAttrs ().hasAttribute <OptionalAttr>())) {
15951592 base = cs.coerceToRValue (base);
15961593 Expr *ref = new (context) DynamicMemberRefExpr (base, dotLoc, memberRef,
15971594 memberLoc);
0 commit comments