Skip to content

Commit e461c25

Browse files
committed
[Macros] Suppress the conformance macro diagnostic in swiftinterfaces.
1 parent 72337ef commit e461c25

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
@@ -7131,11 +7131,17 @@ void AttributeChecker::visitMacroRoleAttr(MacroRoleAttr *attr) {
71317131
break;
71327132
case MacroRole::Peer:
71337133
break;
7134-
case MacroRole::Conformance:
7134+
case MacroRole::Conformance: {
7135+
// Suppress the conformance macro error in swiftinterfaces.
7136+
SourceFile *file = D->getDeclContext()->getParentSourceFile();
7137+
if (file && file->Kind == SourceFileKind::Interface)
7138+
break;
7139+
71357140
diagnoseAndRemoveAttr(attr, diag::conformance_macro)
71367141
.fixItReplace(attr->getRange(),
71377142
"@attached(extension, conformances: <#Protocol#>)");
71387143
break;
7144+
}
71397145
case MacroRole::Extension:
71407146
break;
71417147
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)