@@ -73,9 +73,14 @@ class OverloadChoice {
73
73
// / optional context type, turning a "Decl" kind into
74
74
// / "DeclViaUnwrappedOptional".
75
75
IsDeclViaUnwrappedOptional = 0x02 ,
76
+ // / Indicates that there are viable members found on `Optional`
77
+ // / type and its underlying type. And current overload choice
78
+ // / is a backup one, which should be picked only if members
79
+ // / found directly on `Optional` do not match.
80
+ IsFallbackDeclViaUnwrappedOptional = 0x03 ,
76
81
// / Indicates that this declaration was dynamic, turning a
77
82
// / "Decl" kind into "DeclViaDynamic" kind.
78
- IsDeclViaDynamic = 0x03 ,
83
+ IsDeclViaDynamic = 0x07 ,
79
84
};
80
85
81
86
// / The base type to be used when referencing the declaration
@@ -175,17 +180,23 @@ class OverloadChoice {
175
180
176
181
// / Retrieve an overload choice for a declaration that was found
177
182
// / by unwrapping an optional context type.
183
+ // /
184
+ // / \param isFallback Indicates that this result should be used
185
+ // / as a backup, if member found directly on `Optional` doesn't
186
+ // / match.
178
187
static OverloadChoice
179
- getDeclViaUnwrappedOptional (Type base, ValueDecl *value,
188
+ getDeclViaUnwrappedOptional (Type base, ValueDecl *value, bool isFallback,
180
189
FunctionRefKind functionRefKind) {
181
190
OverloadChoice result;
182
191
result.BaseAndDeclKind .setPointer (base);
183
- result.BaseAndDeclKind .setInt (IsDeclViaUnwrappedOptional);
192
+ result.BaseAndDeclKind .setInt (isFallback
193
+ ? IsFallbackDeclViaUnwrappedOptional
194
+ : IsDeclViaUnwrappedOptional);
184
195
result.DeclOrKind = value;
185
196
result.TheFunctionRefKind = functionRefKind;
186
197
return result;
187
198
}
188
-
199
+
189
200
// / Retrieve an overload choice for a declaration that was found via
190
201
// / dynamic member lookup. The `ValueDecl` is a `subscript(dynamicMember:)`
191
202
// / method.
@@ -219,6 +230,7 @@ class OverloadChoice {
219
230
case IsDeclViaBridge: return OverloadChoiceKind::DeclViaBridge;
220
231
case IsDeclViaDynamic: return OverloadChoiceKind::DeclViaDynamic;
221
232
case IsDeclViaUnwrappedOptional:
233
+ case IsFallbackDeclViaUnwrappedOptional:
222
234
return OverloadChoiceKind::DeclViaUnwrappedOptional;
223
235
default : return OverloadChoiceKind::Decl;
224
236
}
@@ -256,6 +268,12 @@ class OverloadChoice {
256
268
return getKind () == OverloadChoiceKind::KeyPathDynamicMemberLookup;
257
269
}
258
270
271
+ // / Determine whether this member is a backup in case
272
+ // / members found directly on `Optional` didn't match.
273
+ bool isFallbackMemberOnUnwrappedBase () const {
274
+ return BaseAndDeclKind.getInt () == IsFallbackDeclViaUnwrappedOptional;
275
+ }
276
+
259
277
// / Get the name of the overload choice.
260
278
DeclName getName () const ;
261
279
0 commit comments