Skip to content

[Macros] Suppress the conformance macro diagnostic in swiftinterfaces. #67524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7131,11 +7131,17 @@ void AttributeChecker::visitMacroRoleAttr(MacroRoleAttr *attr) {
break;
case MacroRole::Peer:
break;
case MacroRole::Conformance:
case MacroRole::Conformance: {
// Suppress the conformance macro error in swiftinterfaces.
SourceFile *file = D->getDeclContext()->getParentSourceFile();
if (file && file->Kind == SourceFileKind::Interface)
break;

diagnoseAndRemoveAttr(attr, diag::conformance_macro)
.fixItReplace(attr->getRange(),
"@attached(extension, conformances: <#Protocol#>)");
break;
}
case MacroRole::Extension:
break;
default:
Expand Down
5 changes: 5 additions & 0 deletions test/Macros/Inputs/ConformanceMacroLib.swiftinterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -module-name ConformanceMacroLib

@attached(conformance)
public macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMacro")
18 changes: 18 additions & 0 deletions test/Macros/imported_conformance_macro.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// REQUIRES: swift_swift_parser, executable_test

// RUN: %empty-directory(%t)
// 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


// RUN: %target-swift-frontend -compile-module-from-interface -module-name ConformanceMacroLib %S/Inputs/ConformanceMacroLib.swiftinterface -o %t/ConformanceMacroLib.swiftmodule

// 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
// RUN: %FileCheck -check-prefix=CHECK-DUMP %s < %t/expansions-dump.txt

import ConformanceMacroLib

@Equatable
struct S {}

// CHECK-DUMP: extension S: Equatable {
// CHECK-DUMP: }