Skip to content

Commit c72f379

Browse files
committed
[Macros] Downgrade "void return for non-expression macro" error in interfaces
This allows us to continue to accept Swift interface files created with older versions of the Swift 5.9 compiler that emitted a spurious `-> ()` on non-expression macro declarations.
1 parent 1744b46 commit c72f379

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,10 +2077,21 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
20772077
// expression role. Other roles cannot have result types.
20782078
if (auto resultTypeRepr = MD->getResultTypeRepr()) {
20792079
if (!MD->getMacroRoles().contains(MacroRole::Expression)) {
2080-
auto resultType = MD->getResultInterfaceType();
2081-
Ctx.Diags.diagnose(
2082-
MD->arrowLoc, diag::macro_result_type_cannot_be_used, resultType)
2083-
.highlight(resultTypeRepr->getSourceRange());
2080+
auto resultType = MD->getResultInterfaceType(); {
2081+
auto diag = Ctx.Diags.diagnose(
2082+
MD->arrowLoc, diag::macro_result_type_cannot_be_used, resultType);
2083+
diag.highlight(resultTypeRepr->getSourceRange());
2084+
2085+
// In a .swiftinterface file, downgrade this diagnostic to a warning.
2086+
// This allows the compiler to process existing .swiftinterface
2087+
// files that contain this issue.
2088+
if (resultType->isVoid()) {
2089+
if (auto sourceFile = MD->getParentSourceFile())
2090+
if (sourceFile->Kind == SourceFileKind::Interface)
2091+
diag.limitBehavior(DiagnosticBehavior::Warning);
2092+
}
2093+
}
2094+
20842095
Ctx.Diags.diagnose(MD->arrowLoc, diag::macro_make_freestanding_expression)
20852096
.fixItInsert(MD->getAttributeInsertionLoc(false),
20862097
"@freestanding(expression)\n");

0 commit comments

Comments
 (0)