Skip to content

Commit 106f434

Browse files
authored
Merge pull request swiftlang#67524 from hborla/suppress-conformance-macro-error
[Macros] Suppress the conformance macro diagnostic in swiftinterfaces.
2 parents 975b345 + e461c25 commit 106f434

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7137,11 +7137,17 @@ void AttributeChecker::visitMacroRoleAttr(MacroRoleAttr *attr) {
71377137
break;
71387138
case MacroRole::Peer:
71397139
break;
7140-
case MacroRole::Conformance:
7140+
case MacroRole::Conformance: {
7141+
// Suppress the conformance macro error in swiftinterfaces.
7142+
SourceFile *file = D->getDeclContext()->getParentSourceFile();
7143+
if (file && file->Kind == SourceFileKind::Interface)
7144+
break;
7145+
71417146
diagnoseAndRemoveAttr(attr, diag::conformance_macro)
71427147
.fixItReplace(attr->getRange(),
71437148
"@attached(extension, conformances: <#Protocol#>)");
71447149
break;
7150+
}
71457151
case MacroRole::Extension:
71467152
break;
71477153
default:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-module-flags: -module-name ConformanceMacroLib
3+
4+
@attached(conformance)
5+
public macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMacro")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// REQUIRES: swift_swift_parser, executable_test
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
5+
6+
7+
// RUN: %target-swift-frontend -compile-module-from-interface -module-name ConformanceMacroLib %S/Inputs/ConformanceMacroLib.swiftinterface -o %t/ConformanceMacroLib.swiftmodule
8+
9+
// RUN: %target-swift-frontend -swift-version 5 -typecheck -I%t -verify %s -verify-ignore-unknown -load-plugin-library %t/%target-library-name(MacroDefinition) -dump-macro-expansions > %t/expansions-dump.txt 2>&1
10+
// RUN: %FileCheck -check-prefix=CHECK-DUMP %s < %t/expansions-dump.txt
11+
12+
import ConformanceMacroLib
13+
14+
@Equatable
15+
struct S {}
16+
17+
// CHECK-DUMP: extension S: Equatable {
18+
// CHECK-DUMP: }

0 commit comments

Comments
 (0)