mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When a macro that has both 'member' and 'extension' roles is on a type, and both list conforming protocols, the order in which those roles were evaluated in the compiler could change the set of protocols passed to the macro expansion function (via `conformingTo:`). Specifically, if the extension macro was expanded first, the member macro would see the extension providing the conformance to one of its protocols, and not pass down that protocol to the member macro's `conformingTo:`. Ensure that we account for already-expanded extension macros that define conformances. Fixes rdar://137080876.
49 lines
1.6 KiB
Swift
49 lines
1.6 KiB
Swift
// 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
|
|
|
|
// Check for errors first
|
|
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking
|
|
|
|
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -dump-macro-expansions > %t/expansions-dump.txt 2>&1
|
|
// RUN: %FileCheck -check-prefix=CHECK-DUMP %s < %t/expansions-dump.txt
|
|
|
|
|
|
protocol P1 {}
|
|
protocol P2 {}
|
|
|
|
@attached(extension, conformances: P1, P2)
|
|
@attached(member, conformances: P1, P2, names: named(conformances))
|
|
macro ListConformances() = #externalMacro(module: "MacroDefinition", type: "ListConformancesMacro")
|
|
|
|
|
|
// CHECK-DUMP: [ "Root": [ "P1", "P2" ] ]
|
|
// CHECK-DUMP: extension Root: P1
|
|
// CHECK-DUMP: extension Root: P2
|
|
@ListConformances
|
|
class Root {
|
|
// CHECK-DUMP: extension OtherRoot: P1
|
|
// CHECK-DUMP: extension OtherRoot: P2
|
|
var other: OtherRoot?
|
|
}
|
|
|
|
// CHECK-DUMP: [ "P1Root": [ "P2" ] ]
|
|
// CHECK-DUMP-NOT: extension P1Root: P1
|
|
// CHECK-DUMP: extension P1Root: P2
|
|
@ListConformances
|
|
class P1Root: P1 { }
|
|
|
|
// CHECK-DUMP: [ "OtherRoot": [ "P1", "P2" ] ]
|
|
@ListConformances
|
|
class OtherRoot {
|
|
// CHECK-DUMP-NOT: extension OtherP1Root: P1
|
|
// CHECK-DUMP: extension OtherP1Root: P2
|
|
var other: OtherP1Root?
|
|
}
|
|
|
|
// CHECK-DUMP: [ "OtherP1Root": [ "P2" ] ]
|
|
@ListConformances
|
|
class OtherP1Root: P1 { }
|
|
|