Skip to content

Commit f7de3a3

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 7fb1ba9 commit f7de3a3

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

0 commit comments

Comments
 (0)