@@ -1782,6 +1782,14 @@ namespace {
1782
1782
return diags.diagnose (std::forward<ArgTypes>(Args)...);
1783
1783
}
1784
1784
1785
+ template <typename ... ArgTypes>
1786
+ InFlightDiagnostic diagnoseInvalid (TypeRepr *repr,
1787
+ ArgTypes &&... Args) const {
1788
+ auto &diags = Context.Diags ;
1789
+ repr->setInvalid ();
1790
+ return diags.diagnose (std::forward<ArgTypes>(Args)...);
1791
+ }
1792
+
1785
1793
Type resolveAttributedType (AttributedTypeRepr *repr,
1786
1794
TypeResolutionOptions options);
1787
1795
Type resolveAttributedType (TypeAttributes &attrs, TypeRepr *repr,
@@ -2080,18 +2088,21 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2080
2088
2081
2089
// Check for @thick.
2082
2090
if (attrs.has (TAK_thick)) {
2083
- if (storedRepr)
2084
- diagnose (repr->getStartLoc (), diag::sil_metatype_multiple_reprs);
2085
-
2091
+ if (storedRepr) {
2092
+ diagnoseInvalid (repr, repr->getStartLoc (),
2093
+ diag::sil_metatype_multiple_reprs);
2094
+ }
2095
+
2086
2096
storedRepr = MetatypeRepresentation::Thick;
2087
2097
attrs.clearAttribute (TAK_thick);
2088
2098
}
2089
2099
2090
2100
// Check for @objc_metatype.
2091
2101
if (attrs.has (TAK_objc_metatype)) {
2092
- if (storedRepr)
2093
- diagnose (repr->getStartLoc (), diag::sil_metatype_multiple_reprs);
2094
-
2102
+ if (storedRepr) {
2103
+ diagnoseInvalid (repr, repr->getStartLoc (),
2104
+ diag::sil_metatype_multiple_reprs);
2105
+ }
2095
2106
storedRepr = MetatypeRepresentation::ObjC;
2096
2107
attrs.clearAttribute (TAK_objc_metatype);
2097
2108
}
@@ -2119,8 +2130,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2119
2130
2120
2131
auto checkUnsupportedAttr = [&](TypeAttrKind attr) {
2121
2132
if (attrs.has (attr)) {
2122
- diagnose ( attrs.getLoc (attr), diag::unknown_attribute,
2123
- TypeAttributes::getAttrName (attr));
2133
+ diagnoseInvalid (repr, attrs.getLoc (attr), diag::unknown_attribute,
2134
+ TypeAttributes::getAttrName (attr));
2124
2135
attrs.clearAttribute (attr);
2125
2136
}
2126
2137
};
@@ -2170,8 +2181,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2170
2181
auto calleeConvention = ParameterConvention::Direct_Unowned;
2171
2182
if (attrs.has (TAK_callee_owned)) {
2172
2183
if (attrs.has (TAK_callee_guaranteed)) {
2173
- diagnose ( attrs.getLoc (TAK_callee_owned),
2174
- diag::sil_function_repeat_convention, /* callee*/ 2 );
2184
+ diagnoseInvalid (repr, attrs.getLoc (TAK_callee_owned),
2185
+ diag::sil_function_repeat_convention, /* callee*/ 2 );
2175
2186
}
2176
2187
calleeConvention = ParameterConvention::Direct_Owned;
2177
2188
} else if (attrs.has (TAK_callee_guaranteed)) {
@@ -2197,8 +2208,9 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2197
2208
SILFunctionType::Representation::WitnessMethod)
2198
2209
.Default (None);
2199
2210
if (!parsedRep) {
2200
- diagnose (attrs.getLoc (TAK_convention),
2201
- diag::unsupported_sil_convention, attrs.getConventionName ());
2211
+ diagnoseInvalid (repr, attrs.getLoc (TAK_convention),
2212
+ diag::unsupported_sil_convention,
2213
+ attrs.getConventionName ());
2202
2214
rep = SILFunctionType::Representation::Thin;
2203
2215
} else {
2204
2216
rep = *parsedRep;
@@ -2214,8 +2226,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2214
2226
2215
2227
if (attrs.has (TAK_differentiable) &&
2216
2228
!Context.LangOpts .EnableExperimentalDifferentiableProgramming ) {
2217
- diagnose ( attrs.getLoc (TAK_differentiable),
2218
- diag::experimental_differentiable_programming_disabled);
2229
+ diagnoseInvalid (repr, attrs.getLoc (TAK_differentiable),
2230
+ diag::experimental_differentiable_programming_disabled);
2219
2231
}
2220
2232
2221
2233
DifferentiabilityKind diffKind = DifferentiabilityKind::NonDifferentiable;
@@ -2246,8 +2258,9 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2246
2258
.Case (" c" , FunctionType::Representation::CFunctionPointer)
2247
2259
.Default (None);
2248
2260
if (!parsedRep) {
2249
- diagnose (attrs.getLoc (TAK_convention), diag::unsupported_convention,
2250
- attrs.getConventionName ());
2261
+ diagnoseInvalid (repr, attrs.getLoc (TAK_convention),
2262
+ diag::unsupported_convention,
2263
+ attrs.getConventionName ());
2251
2264
rep = FunctionType::Representation::Swift;
2252
2265
} else {
2253
2266
rep = *parsedRep;
@@ -2256,8 +2269,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2256
2269
2257
2270
if (attrs.has (TAK_differentiable) &&
2258
2271
!Context.LangOpts .EnableExperimentalDifferentiableProgramming ) {
2259
- diagnose ( attrs.getLoc (TAK_differentiable),
2260
- diag::experimental_differentiable_programming_disabled);
2272
+ diagnoseInvalid (repr, attrs.getLoc (TAK_differentiable),
2273
+ diag::experimental_differentiable_programming_disabled);
2261
2274
}
2262
2275
2263
2276
DifferentiabilityKind diffKind = DifferentiabilityKind::NonDifferentiable;
@@ -2279,21 +2292,21 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2279
2292
if (attrs.hasConvention ()) {
2280
2293
if (attrs.getConventionName () == " c" ||
2281
2294
attrs.getConventionName () == " block" ) {
2282
- diagnose ( attrs.getLoc (TAK_convention),
2283
- diag::invalid_autoclosure_and_convention_attributes,
2284
- attrs.getConventionName ());
2295
+ diagnoseInvalid (repr, attrs.getLoc (TAK_convention),
2296
+ diag::invalid_autoclosure_and_convention_attributes,
2297
+ attrs.getConventionName ());
2285
2298
attrs.clearAttribute (TAK_convention);
2286
2299
didDiagnose = true ;
2287
2300
}
2288
2301
} else if (options.is (TypeResolverContext::VariadicFunctionInput) &&
2289
2302
!options.hasBase (TypeResolverContext::EnumElementDecl)) {
2290
- diagnose ( attrs.getLoc (TAK_autoclosure),
2291
- diag::attr_not_on_variadic_parameters, " @autoclosure" );
2303
+ diagnoseInvalid (repr, attrs.getLoc (TAK_autoclosure),
2304
+ diag::attr_not_on_variadic_parameters, " @autoclosure" );
2292
2305
attrs.clearAttribute (TAK_autoclosure);
2293
2306
didDiagnose = true ;
2294
2307
} else if (!options.is (TypeResolverContext::FunctionInput)) {
2295
- diagnose ( attrs.getLoc (TAK_autoclosure), diag::attr_only_on_parameters ,
2296
- " @autoclosure" );
2308
+ diagnoseInvalid (repr, attrs.getLoc (TAK_autoclosure),
2309
+ diag::attr_only_on_parameters, " @autoclosure" );
2297
2310
attrs.clearAttribute (TAK_autoclosure);
2298
2311
didDiagnose = true ;
2299
2312
}
@@ -2328,12 +2341,13 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2328
2341
auto loc = attrs.getLoc (TAK_escaping);
2329
2342
auto attrRange = getTypeAttrRangeWithAt (Context, loc);
2330
2343
2331
- diagnose ( loc, diag::escaping_non_function_parameter)
2332
- .fixItRemove (attrRange);
2344
+ diagnoseInvalid (repr, loc, diag::escaping_non_function_parameter)
2345
+ .fixItRemove (attrRange);
2333
2346
2334
2347
// Try to find a helpful note based on how the type is being used
2335
2348
if (options.is (TypeResolverContext::ImmediateOptionalTypeArgument)) {
2336
- diagnose (repr->getLoc (), diag::escaping_optional_type_argument);
2349
+ diagnoseInvalid (repr, repr->getLoc (),
2350
+ diag::escaping_optional_type_argument);
2337
2351
}
2338
2352
}
2339
2353
@@ -2349,16 +2363,17 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2349
2363
// @autoclosure is going to be diagnosed when type of
2350
2364
// the parameter is validated, because that attribute
2351
2365
// applies to the declaration now.
2366
+ repr->setInvalid ();
2352
2367
attrs.clearAttribute (TAK_autoclosure);
2353
2368
}
2354
2369
2355
2370
for (auto i : FunctionAttrs) {
2356
2371
if (!attrs.has (i))
2357
2372
continue ;
2358
2373
2359
- auto diag = diagnose ( attrs.getLoc (i),
2360
- diag::attribute_requires_function_type,
2361
- TypeAttributes::getAttrName (i));
2374
+ auto diag = diagnoseInvalid (repr, attrs.getLoc (i),
2375
+ diag::attribute_requires_function_type,
2376
+ TypeAttributes::getAttrName (i));
2362
2377
2363
2378
// If we see @escaping among the attributes on this type, because it isn't
2364
2379
// a function type, we'll remove it.
@@ -2368,7 +2383,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2368
2383
// Specialize the diagnostic for Optionals.
2369
2384
if (ty->getOptionalObjectType ()) {
2370
2385
diag.flush ();
2371
- diagnose (repr->getLoc (), diag::escaping_optional_type_argument);
2386
+ diagnoseInvalid (repr, repr->getLoc (),
2387
+ diag::escaping_optional_type_argument);
2372
2388
}
2373
2389
}
2374
2390
attrs.clearAttribute (i);
@@ -2398,7 +2414,8 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2398
2414
// In SIL, handle @opened (n), which creates an existential archetype.
2399
2415
if (attrs.has (TAK_opened)) {
2400
2416
if (!ty->isExistentialType ()) {
2401
- diagnose (attrs.getLoc (TAK_opened), diag::opened_non_protocol, ty);
2417
+ diagnoseInvalid (repr, attrs.getLoc (TAK_opened), diag::opened_non_protocol,
2418
+ ty);
2402
2419
} else {
2403
2420
ty = OpenedArchetypeType::get (ty, attrs.OpenedID );
2404
2421
}
@@ -2438,9 +2455,10 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
2438
2455
}
2439
2456
2440
2457
for (unsigned i = 0 ; i != TypeAttrKind::TAK_Count; ++i)
2441
- if (attrs.has ((TypeAttrKind)i))
2442
- diagnose (attrs.getLoc ((TypeAttrKind)i),
2443
- diag::attribute_does_not_apply_to_type);
2458
+ if (attrs.has ((TypeAttrKind)i)) {
2459
+ diagnoseInvalid (repr, attrs.getLoc ((TypeAttrKind)i),
2460
+ diag::attribute_does_not_apply_to_type);
2461
+ }
2444
2462
2445
2463
return ty;
2446
2464
}
@@ -3080,8 +3098,7 @@ Type TypeResolver::resolveSpecifierTypeRepr(SpecifierTypeRepr *repr,
3080
3098
default :
3081
3099
llvm_unreachable (" unknown SpecifierTypeRepr kind" );
3082
3100
}
3083
- diagnose (repr->getSpecifierLoc (), diagID, name);
3084
- repr->setInvalid ();
3101
+ diagnoseInvalid (repr, repr->getSpecifierLoc (), diagID, name);
3085
3102
return ErrorType::get (Context);
3086
3103
}
3087
3104
0 commit comments