Sema: Use ForeignLanguage directly in diagnostic definitions

This commit is contained in:
Alexis Laferrière
2025-05-14 12:53:57 -07:00
parent 9c7f0c7550
commit bb99891648
4 changed files with 11 additions and 10 deletions

View File

@@ -55,6 +55,7 @@ namespace swift {
} // end namespace detail
enum class StaticSpellingKind : uint8_t;
enum class ForeignLanguage : uint8_t;
namespace diag {

View File

@@ -6612,19 +6612,19 @@ ERROR(objc_invalid_on_func_variadic,none,
ERROR(objc_invalid_on_func_inout,none,
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because inout "
"parameters cannot be represented in %" FOREIGN_LANG_SELECT "2",
(const AbstractFunctionDecl*, unsigned, unsigned))
(const AbstractFunctionDecl*, unsigned, ForeignLanguage))
ERROR(objc_invalid_on_func_param_type,none,
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "2 because the type of the "
"parameter %1 cannot be represented in %" FOREIGN_LANG_SELECT "3",
(const AbstractFunctionDecl*, unsigned, unsigned, unsigned))
(const AbstractFunctionDecl*, unsigned, unsigned, ForeignLanguage))
ERROR(objc_invalid_on_func_single_param_type,none,
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because the type of the "
"parameter cannot be represented in %" FOREIGN_LANG_SELECT "2",
(const AbstractFunctionDecl*, unsigned, unsigned))
(const AbstractFunctionDecl*, unsigned, ForeignLanguage))
ERROR(objc_invalid_on_func_result_type,none,
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because its result type "
"cannot be represented in %" FOREIGN_LANG_SELECT "2",
(const AbstractFunctionDecl*, unsigned, unsigned))
(const AbstractFunctionDecl*, unsigned, ForeignLanguage))
ERROR(objc_invalid_on_foreign_class,none,
"method cannot be %" OBJC_ATTR_SELECT "0 because Core Foundation "
"types are not classes in Objective-C", (unsigned))

View File

@@ -161,7 +161,7 @@ inline SubstOptions operator|(SubstFlags lhs, SubstFlags rhs) {
/// Enumeration describing foreign languages to which Swift may be
/// bridged.
enum class ForeignLanguage {
enum class ForeignLanguage : uint8_t {
C,
ObjectiveC,
};

View File

@@ -305,13 +305,13 @@ static void diagnoseFunctionParamNotRepresentable(
softenIfAccessNote(AFD, Reason.getAttr(),
AFD->diagnose(diag::objc_invalid_on_func_single_param_type,
AFD, getObjCDiagnosticAttrKind(Reason),
(unsigned)language)
language)
.limitBehavior(behavior));
} else {
softenIfAccessNote(AFD, Reason.getAttr(),
AFD->diagnose(diag::objc_invalid_on_func_param_type,
AFD, ParamIndex + 1, getObjCDiagnosticAttrKind(Reason),
(unsigned)language)
language)
.limitBehavior(behavior));
}
SourceRange SR;
@@ -358,7 +358,7 @@ static bool isParamListRepresentableInLanguage(const AbstractFunctionDecl *AFD,
softenIfAccessNote(AFD, Reason.getAttr(),
diags.diagnose(param->getStartLoc(), diag::objc_invalid_on_func_inout,
AFD, getObjCDiagnosticAttrKind(Reason),
(unsigned)language)
language)
.highlight(param->getSourceRange())
.limitBehavior(behavior));
Reason.describe(AFD);
@@ -800,7 +800,7 @@ bool swift::isRepresentableInLanguage(
softenIfAccessNote(AFD, Reason.getAttr(),
AFD->diagnose(diag::objc_invalid_on_func_result_type,
FD, getObjCDiagnosticAttrKind(Reason),
(unsigned)language)
language)
.limitBehavior(behavior));
diagnoseTypeNotRepresentableInObjC(FD, ResultType,
FD->getResultTypeSourceRange(),
@@ -857,7 +857,7 @@ bool swift::isRepresentableInLanguage(
softenIfAccessNote(AFD, Reason.getAttr(),
AFD->diagnose(diag::objc_invalid_on_func_result_type,
FD, getObjCDiagnosticAttrKind(Reason),
(unsigned)language)
language)
.limitBehavior(behavior));
diagnoseTypeNotRepresentableInObjC(FD, type,
FD->getResultTypeSourceRange(),