mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
As it stands, for extension macros which add protocol conformances, the list of protocols specified on the macro's 'conformances:' parameter gets added in its entirety to the list of a nominal type's protocols in 'ConformanceLookupTable::addMacroGeneratedProtocols'. Whereas the macro itself, may only add *some* of the specified conformances. This means that `getAllProtocols` may contain a super-set of protocols captured in `getAllConformances`, some of which may not actually be generated by the macro. This change narrowly fixes ConstExtract to query actual generated conformances. Though, potentially we should make 'ConformanceLookupTable::addMacroGeneratedProtocols' behave in a way that reflects the protocols the macro actually adds the conformances to, instead of the ones it may add conformances to. Resolves rdar://130316531
29 lines
1.3 KiB
Swift
29 lines
1.3 KiB
Swift
// REQUIRES: swift_swift_parser
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: echo "[MyProto]" > %t/protocols.json
|
|
|
|
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/Macros.swift -g -no-toolchain-stdlib-rpath
|
|
|
|
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractFromMacroExpansion.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s -load-plugin-library %t/%target-library-name(MacroDefinition)
|
|
// RUN: cat %t/ExtractFromMacroExpansion.swiftconstvalues 2>&1 | %FileCheck %s
|
|
|
|
protocol MyProto { }
|
|
protocol MyExtraProto { }
|
|
|
|
@attached(extension, conformances: MyProto, MyExtraProto)
|
|
macro specificExtensionMacro() = #externalMacro(module: "MacroDefinition", type: "AddSpecificExtensionMacro")
|
|
|
|
@specificExtensionMacro
|
|
struct MyStruct {
|
|
struct Inner { }
|
|
}
|
|
|
|
// CHECK: "typeName": "ExtractMacroExpandedConformances.MyStruct",
|
|
// CHECK: "mangledTypeName": "32ExtractMacroExpandedConformances8MyStructV",
|
|
// CHECK: "kind": "struct",
|
|
// CHECK: "conformances": [
|
|
// CHECK-DAG: "Swift.Sendable",
|
|
// CHECK-DAG: "Swift.BitwiseCopyable",
|
|
// CHECK-DAG: "ExtractMacroExpandedConformances.MyProto"
|
|
// CHECK-NOT: "ExtractMacroExpandedConformances.MyExtraProto"
|