@@ -223,9 +223,17 @@ static void diagnoseTypeNotRepresentableInObjC(const DeclContext *DC,
223223
224224 // Special diagnostic for enums.
225225 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+ }
229237 return ;
230238 }
231239
@@ -1766,19 +1774,18 @@ static bool isCIntegerType(Type type) {
17661774}
17671775
17681776// / Determine whether the given enum should be @objc.
1769- static bool isEnumObjC (EnumDecl *enumDecl) {
1777+ static bool isEnumObjC (EnumDecl *enumDecl, DeclAttribute *attr ) {
17701778 // FIXME: Use shouldMarkAsObjC once it loses it's TypeChecker argument.
17711779
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.
17741781 if (!attr)
17751782 return false ;
17761783
17771784 Type rawType = enumDecl->getRawType ();
17781785
1779- // @objc enums must have a raw type.
1786+ // @objc/@cdecl enums must have a raw type.
17801787 if (!rawType) {
1781- enumDecl->diagnose (diag::objc_enum_no_raw_type);
1788+ enumDecl->diagnose (diag::objc_enum_no_raw_type, attr );
17821789 return false ;
17831790 }
17841791
@@ -1791,7 +1798,7 @@ static bool isEnumObjC(EnumDecl *enumDecl) {
17911798 SourceRange errorRange;
17921799 if (!enumDecl->getInherited ().empty ())
17931800 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)
17951802 .highlight (errorRange);
17961803 return false ;
17971804 }
@@ -1801,7 +1808,8 @@ static bool isEnumObjC(EnumDecl *enumDecl) {
18011808 enumDecl->diagnose (diag::empty_enum_raw_type);
18021809 }
18031810
1804- checkObjCNameValidity (enumDecl, attr);
1811+ if (auto objcAttr = dyn_cast<ObjCAttr>(attr))
1812+ checkObjCNameValidity (enumDecl, objcAttr);
18051813 return true ;
18061814}
18071815
@@ -1842,9 +1850,9 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
18421850 } else if (auto enumDecl = dyn_cast<EnumDecl>(VD)) {
18431851 // Enums can be @objc so long as they have a raw type that is representable
18441852 // 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 );
18481856 } else if (auto enumElement = dyn_cast<EnumElementDecl>(VD)) {
18491857 // Enum elements can be @objc so long as the containing enum is @objc.
18501858 if (enumElement->getParentEnum ()->isObjC ()) {
@@ -4209,9 +4217,9 @@ evaluate(Evaluator &evaluator, Decl *D) const {
42094217}
42104218
42114219evaluator::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 {
42154223 auto &ctx = FD->getASTContext ();
42164224
42174225 auto lang = FD->getCDeclKind ();
@@ -4236,6 +4244,14 @@ TypeCheckCDeclAttributeRequest::evaluate(Evaluator &evaluator,
42364244 } else {
42374245 reason.setAttrInvalid ();
42384246 }
4247+ return {};
4248+ }
42394249
4250+ evaluator::SideEffect
4251+ TypeCheckCDeclEnumRequest::evaluate (Evaluator &evaluator,
4252+ EnumDecl *ED,
4253+ CDeclAttr *attr) const {
4254+ // Apply @objc's logic.
4255+ isEnumObjC (ED, attr);
42404256 return {};
42414257}
0 commit comments