@@ -223,9 +223,17 @@ static void diagnoseTypeNotRepresentableInObjC(const DeclContext *DC,
223
223
224
224
// Special diagnostic for enums.
225
225
if (T->is <EnumType>()) {
226
- diags.diagnose (TypeRange.Start , diag::not_objc_swift_enum)
227
- .highlight (TypeRange)
228
- .limitBehavior (behavior);
226
+ if (DC->getASTContext ().LangOpts .hasFeature (Feature::CDecl)) {
227
+ // New dialog mentioning @cdecl.
228
+ diags.diagnose (TypeRange.Start , diag::not_cdecl_or_objc_swift_enum,
229
+ language)
230
+ .highlight (TypeRange)
231
+ .limitBehavior (behavior);
232
+ } else {
233
+ diags.diagnose (TypeRange.Start , diag::not_objc_swift_enum)
234
+ .highlight (TypeRange)
235
+ .limitBehavior (behavior);
236
+ }
229
237
return ;
230
238
}
231
239
@@ -1766,19 +1774,18 @@ static bool isCIntegerType(Type type) {
1766
1774
}
1767
1775
1768
1776
// / Determine whether the given enum should be @objc.
1769
- static bool isEnumObjC (EnumDecl *enumDecl) {
1777
+ static bool isEnumObjC (EnumDecl *enumDecl, DeclAttribute *attr ) {
1770
1778
// FIXME: Use shouldMarkAsObjC once it loses it's TypeChecker argument.
1771
1779
1772
- // If there is no @objc attribute, it's not @objc.
1773
- auto attr = enumDecl->getAttrs ().getAttribute <ObjCAttr>();
1780
+ // If there is no @objc or @cdecl attribute, skip it.
1774
1781
if (!attr)
1775
1782
return false ;
1776
1783
1777
1784
Type rawType = enumDecl->getRawType ();
1778
1785
1779
- // @objc enums must have a raw type.
1786
+ // @objc/@cdecl enums must have a raw type.
1780
1787
if (!rawType) {
1781
- enumDecl->diagnose (diag::objc_enum_no_raw_type);
1788
+ enumDecl->diagnose (diag::objc_enum_no_raw_type, attr );
1782
1789
return false ;
1783
1790
}
1784
1791
@@ -1791,7 +1798,7 @@ static bool isEnumObjC(EnumDecl *enumDecl) {
1791
1798
SourceRange errorRange;
1792
1799
if (!enumDecl->getInherited ().empty ())
1793
1800
errorRange = enumDecl->getInherited ().getEntry (0 ).getSourceRange ();
1794
- enumDecl->diagnose (diag::objc_enum_raw_type_not_integer, rawType)
1801
+ enumDecl->diagnose (diag::objc_enum_raw_type_not_integer, attr, rawType)
1795
1802
.highlight (errorRange);
1796
1803
return false ;
1797
1804
}
@@ -1801,7 +1808,8 @@ static bool isEnumObjC(EnumDecl *enumDecl) {
1801
1808
enumDecl->diagnose (diag::empty_enum_raw_type);
1802
1809
}
1803
1810
1804
- checkObjCNameValidity (enumDecl, attr);
1811
+ if (auto objcAttr = dyn_cast<ObjCAttr>(attr))
1812
+ checkObjCNameValidity (enumDecl, objcAttr);
1805
1813
return true ;
1806
1814
}
1807
1815
@@ -1842,9 +1850,9 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
1842
1850
} else if (auto enumDecl = dyn_cast<EnumDecl>(VD)) {
1843
1851
// Enums can be @objc so long as they have a raw type that is representable
1844
1852
// as an arithmetic type in C.
1845
- if ( isEnumObjC (enumDecl))
1846
- isObjC = objCReasonForObjCAttr (
1847
- enumDecl-> getAttrs (). getAttribute <ObjCAttr>() );
1853
+ auto attr = enumDecl-> getAttrs (). getAttribute <ObjCAttr>();
1854
+ if (attr && isEnumObjC (enumDecl, attr))
1855
+ isObjC = objCReasonForObjCAttr (attr );
1848
1856
} else if (auto enumElement = dyn_cast<EnumElementDecl>(VD)) {
1849
1857
// Enum elements can be @objc so long as the containing enum is @objc.
1850
1858
if (enumElement->getParentEnum ()->isObjC ()) {
@@ -4209,9 +4217,9 @@ evaluate(Evaluator &evaluator, Decl *D) const {
4209
4217
}
4210
4218
4211
4219
evaluator::SideEffect
4212
- TypeCheckCDeclAttributeRequest ::evaluate (Evaluator &evaluator,
4213
- FuncDecl *FD,
4214
- CDeclAttr *attr) const {
4220
+ TypeCheckCDeclFunctionRequest ::evaluate (Evaluator &evaluator,
4221
+ FuncDecl *FD,
4222
+ CDeclAttr *attr) const {
4215
4223
auto &ctx = FD->getASTContext ();
4216
4224
4217
4225
auto lang = FD->getCDeclKind ();
@@ -4236,6 +4244,14 @@ TypeCheckCDeclAttributeRequest::evaluate(Evaluator &evaluator,
4236
4244
} else {
4237
4245
reason.setAttrInvalid ();
4238
4246
}
4247
+ return {};
4248
+ }
4239
4249
4250
+ evaluator::SideEffect
4251
+ TypeCheckCDeclEnumRequest::evaluate (Evaluator &evaluator,
4252
+ EnumDecl *ED,
4253
+ CDeclAttr *attr) const {
4254
+ // Apply @objc's logic.
4255
+ isEnumObjC (ED, attr);
4240
4256
return {};
4241
4257
}
0 commit comments