@@ -1058,8 +1058,8 @@ void TypeChecker::checkDeclAttributes(Decl *D) {
1058
1058
// / as one of the following: `dynamicallyCall(withArguments:)` or
1059
1059
// / `dynamicallyCall(withKeywordArguments:)`.
1060
1060
bool swift::isValidDynamicCallableMethod (FuncDecl *decl, DeclContext *DC,
1061
- TypeChecker &TC,
1062
1061
bool hasKeywordArguments) {
1062
+ auto &ctx = decl->getASTContext ();
1063
1063
// There are two cases to check.
1064
1064
// 1. `dynamicallyCall(withArguments:)`.
1065
1065
// In this case, the method is valid if the argument has type `A` where
@@ -1081,43 +1081,41 @@ bool swift::isValidDynamicCallableMethod(FuncDecl *decl, DeclContext *DC,
1081
1081
// `ExpressibleByArrayLiteral`.
1082
1082
if (!hasKeywordArguments) {
1083
1083
auto arrayLitProto =
1084
- TC. Context .getProtocol (KnownProtocolKind::ExpressibleByArrayLiteral);
1084
+ ctx .getProtocol (KnownProtocolKind::ExpressibleByArrayLiteral);
1085
1085
return TypeChecker::conformsToProtocol (argType, arrayLitProto, DC,
1086
1086
ConformanceCheckOptions ()).hasValue ();
1087
1087
}
1088
1088
// If keyword arguments, check that argument type conforms to
1089
1089
// `ExpressibleByDictionaryLiteral` and that the `Key` associated type
1090
1090
// conforms to `ExpressibleByStringLiteral`.
1091
1091
auto stringLitProtocol =
1092
- TC. Context .getProtocol (KnownProtocolKind::ExpressibleByStringLiteral);
1092
+ ctx .getProtocol (KnownProtocolKind::ExpressibleByStringLiteral);
1093
1093
auto dictLitProto =
1094
- TC. Context .getProtocol (KnownProtocolKind::ExpressibleByDictionaryLiteral);
1094
+ ctx .getProtocol (KnownProtocolKind::ExpressibleByDictionaryLiteral);
1095
1095
auto dictConf = TypeChecker::conformsToProtocol (argType, dictLitProto, DC,
1096
1096
ConformanceCheckOptions ());
1097
1097
if (!dictConf) return false ;
1098
- auto keyType = dictConf.getValue ().getTypeWitnessByName (
1099
- argType, TC.Context .Id_Key );
1098
+ auto keyType = dictConf.getValue ().getTypeWitnessByName (argType, ctx.Id_Key );
1100
1099
return TypeChecker::conformsToProtocol (keyType, stringLitProtocol, DC,
1101
1100
ConformanceCheckOptions ()).hasValue ();
1102
1101
}
1103
1102
1104
1103
// / Returns true if the given nominal type has a valid implementation of a
1105
1104
// / @dynamicCallable attribute requirement with the given argument name.
1106
- static bool hasValidDynamicCallableMethod (TypeChecker &TC,
1107
- NominalTypeDecl *decl,
1105
+ static bool hasValidDynamicCallableMethod (NominalTypeDecl *decl,
1108
1106
Identifier argumentName,
1109
1107
bool hasKeywordArgs) {
1108
+ auto &ctx = decl->getASTContext ();
1110
1109
auto declType = decl->getDeclaredType ();
1111
- auto methodName = DeclName (TC.Context ,
1112
- DeclBaseName (TC.Context .Id_dynamicallyCall ),
1110
+ auto methodName = DeclName (ctx, DeclBaseName (ctx.Id_dynamicallyCall ),
1113
1111
{ argumentName });
1114
- auto candidates = TC. lookupMember (decl, declType, methodName);
1112
+ auto candidates = TypeChecker:: lookupMember (decl, declType, methodName);
1115
1113
if (candidates.empty ()) return false ;
1116
1114
1117
1115
// Filter valid candidates.
1118
1116
candidates.filter ([&](LookupResultEntry entry, bool isOuter) {
1119
1117
auto candidate = cast<FuncDecl>(entry.getValueDecl ());
1120
- return isValidDynamicCallableMethod (candidate, decl, TC, hasKeywordArgs);
1118
+ return isValidDynamicCallableMethod (candidate, decl, hasKeywordArgs);
1121
1119
});
1122
1120
1123
1121
// If there are no valid candidates, return false.
@@ -1133,10 +1131,10 @@ visitDynamicCallableAttr(DynamicCallableAttr *attr) {
1133
1131
1134
1132
bool hasValidMethod = false ;
1135
1133
hasValidMethod |=
1136
- hasValidDynamicCallableMethod (TC, decl, TC.Context .Id_withArguments ,
1134
+ hasValidDynamicCallableMethod (decl, TC.Context .Id_withArguments ,
1137
1135
/* hasKeywordArgs*/ false );
1138
1136
hasValidMethod |=
1139
- hasValidDynamicCallableMethod (TC, decl, TC.Context .Id_withKeywordArguments ,
1137
+ hasValidDynamicCallableMethod (decl, TC.Context .Id_withKeywordArguments ,
1140
1138
/* hasKeywordArgs*/ true );
1141
1139
if (!hasValidMethod) {
1142
1140
TC.diagnose (attr->getLocation (), diag::invalid_dynamic_callable_type, type);
@@ -1167,48 +1165,48 @@ static bool hasSingleNonVariadicParam(SubscriptDecl *decl,
1167
1165
// / The method is given to be defined as `subscript(dynamicMember:)`.
1168
1166
bool swift::isValidDynamicMemberLookupSubscript (SubscriptDecl *decl,
1169
1167
DeclContext *DC,
1170
- TypeChecker &TC,
1171
1168
bool ignoreLabel) {
1172
1169
// It could be
1173
1170
// - `subscript(dynamicMember: {Writable}KeyPath<...>)`; or
1174
1171
// - `subscript(dynamicMember: String*)`
1175
- return isValidKeyPathDynamicMemberLookup (decl, TC, ignoreLabel) ||
1176
- isValidStringDynamicMemberLookup (decl, DC, TC, ignoreLabel);
1172
+ return isValidKeyPathDynamicMemberLookup (decl, ignoreLabel) ||
1173
+ isValidStringDynamicMemberLookup (decl, DC, ignoreLabel);
1177
1174
}
1178
1175
1179
1176
bool swift::isValidStringDynamicMemberLookup (SubscriptDecl *decl,
1180
- DeclContext *DC, TypeChecker &TC,
1177
+ DeclContext *DC,
1181
1178
bool ignoreLabel) {
1179
+ auto &ctx = decl->getASTContext ();
1182
1180
// There are two requirements:
1183
1181
// - The subscript method has exactly one, non-variadic parameter.
1184
1182
// - The parameter type conforms to `ExpressibleByStringLiteral`.
1185
- if (!hasSingleNonVariadicParam (decl, TC. Context .Id_dynamicMember ,
1183
+ if (!hasSingleNonVariadicParam (decl, ctx .Id_dynamicMember ,
1186
1184
ignoreLabel))
1187
1185
return false ;
1188
1186
1189
1187
const auto *param = decl->getIndices ()->get (0 );
1190
1188
auto paramType = param->getType ();
1191
1189
1192
1190
auto stringLitProto =
1193
- TC. Context .getProtocol (KnownProtocolKind::ExpressibleByStringLiteral);
1191
+ ctx .getProtocol (KnownProtocolKind::ExpressibleByStringLiteral);
1194
1192
1195
1193
// If this is `subscript(dynamicMember: String*)`
1196
1194
return bool (TypeChecker::conformsToProtocol (paramType, stringLitProto, DC,
1197
1195
ConformanceCheckOptions ()));
1198
1196
}
1199
1197
1200
1198
bool swift::isValidKeyPathDynamicMemberLookup (SubscriptDecl *decl,
1201
- TypeChecker &TC,
1202
1199
bool ignoreLabel) {
1203
- if (!hasSingleNonVariadicParam (decl, TC.Context .Id_dynamicMember ,
1200
+ auto &ctx = decl->getASTContext ();
1201
+ if (!hasSingleNonVariadicParam (decl, ctx.Id_dynamicMember ,
1204
1202
ignoreLabel))
1205
1203
return false ;
1206
1204
1207
1205
const auto *param = decl->getIndices ()->get (0 );
1208
1206
if (auto NTD = param->getType ()->getAnyNominal ()) {
1209
- return NTD == TC. Context .getKeyPathDecl () ||
1210
- NTD == TC. Context .getWritableKeyPathDecl () ||
1211
- NTD == TC. Context .getReferenceWritableKeyPathDecl ();
1207
+ return NTD == ctx .getKeyPathDecl () ||
1208
+ NTD == ctx .getWritableKeyPathDecl () ||
1209
+ NTD == ctx .getReferenceWritableKeyPathDecl ();
1212
1210
}
1213
1211
return false ;
1214
1212
}
@@ -1245,7 +1243,7 @@ visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr) {
1245
1243
auto cand = cast<SubscriptDecl>(entry.getValueDecl ());
1246
1244
// FIXME(InterfaceTypeRequest): Remove this.
1247
1245
(void )cand->getInterfaceType ();
1248
- return isValidDynamicMemberLookupSubscript (cand, decl, TC );
1246
+ return isValidDynamicMemberLookupSubscript (cand, decl);
1249
1247
});
1250
1248
1251
1249
if (candidates.empty ()) {
@@ -1269,7 +1267,7 @@ visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr) {
1269
1267
auto cand = cast<SubscriptDecl>(entry.getValueDecl ());
1270
1268
// FIXME(InterfaceTypeRequest): Remove this.
1271
1269
(void )cand->getInterfaceType ();
1272
- return isValidDynamicMemberLookupSubscript (cand, decl, TC,
1270
+ return isValidDynamicMemberLookupSubscript (cand, decl,
1273
1271
/* ignoreLabel*/ true );
1274
1272
});
1275
1273
0 commit comments