mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Extract decl in macro added extensions
This commit is contained in:
@@ -560,6 +560,11 @@ gatherConstValuesForPrimary(const std::unordered_set<std::string> &Protocols,
|
||||
ConformanceDecls);
|
||||
for (auto D : SF->getTopLevelDecls())
|
||||
D->walk(ConformanceCollector);
|
||||
// Visit macro expanded extensions
|
||||
if (auto *synthesizedSF = SF->getSynthesizedFile())
|
||||
for (auto D : synthesizedSF->getTopLevelDecls())
|
||||
if (isa<ExtensionDecl>(D))
|
||||
D->walk(ConformanceCollector);
|
||||
|
||||
for (auto *CD : ConformanceDecls)
|
||||
Result.emplace_back(evaluateOrDefault(
|
||||
|
||||
@@ -15,7 +15,7 @@ macro AddMacroAddedStruct() = #externalMacro(module: "MacroDefinition", type: "A
|
||||
@freestanding(declaration, names: named(macroAddedVar))
|
||||
macro AddMacroAddedVar() = #externalMacro(module: "MacroDefinition", type: "AddVarDeclMacro")
|
||||
|
||||
@attached(extension, conformances: MyProto, names: prefixed(_extension_))
|
||||
@attached(extension, conformances: MyProto, names: prefixed(_extension_), named(_Extension_MyProto))
|
||||
macro AddExtension() = #externalMacro(module: "MacroDefinition", type: "AddExtensionMacro")
|
||||
|
||||
@attached(peer, names: prefixed(_peer_))
|
||||
@@ -175,3 +175,42 @@ extension MyStruct {
|
||||
// CHECK: "type": "Swift.Int",
|
||||
// CHECK: "valueKind": "RawLiteral",
|
||||
// CHECK: "value": "3"
|
||||
|
||||
|
||||
// CHECK: "typeName": "ExtractFromMacroExpansion.MacroAddedStruct._Extension_MyProto",
|
||||
// CHECK: "properties": [
|
||||
// CHECK: "label": "nested",
|
||||
// CHECK: "type": "Swift.Int",
|
||||
// CHECK: "valueKind": "RawLiteral",
|
||||
// CHECK: "value": "8"
|
||||
|
||||
|
||||
// CHECK: "typeName": "ExtractFromMacroExpansion._Peer_MyStruct._Extension_MyProto",
|
||||
// CHECK: "properties": [
|
||||
// CHECK: "label": "nested",
|
||||
// CHECK: "type": "Swift.Int",
|
||||
// CHECK: "valueKind": "RawLiteral",
|
||||
// CHECK: "value": "8"
|
||||
|
||||
// CHECK: "typeName": "ExtractFromMacroExpansion.MyStruct._Extension_MyProto",
|
||||
// CHECK: "properties": [
|
||||
// CHECK: "label": "nested",
|
||||
// CHECK: "type": "Swift.Int",
|
||||
// CHECK: "valueKind": "RawLiteral",
|
||||
// CHECK: "value": "8"
|
||||
|
||||
|
||||
// CHECK: "typeName": "ExtractFromMacroExpansion.MyStruct._Peer_Inner._Extension_MyProto",
|
||||
// CHECK: "properties": [
|
||||
// CHECK: "label": "nested",
|
||||
// CHECK: "type": "Swift.Int",
|
||||
// CHECK: "valueKind": "RawLiteral",
|
||||
// CHECK: "value": "8"
|
||||
|
||||
|
||||
// CHECK: "typeName": "ExtractFromMacroExpansion.MyStruct.Inner._Extension_MyProto",
|
||||
// CHECK: "properties": [
|
||||
// CHECK: "label": "nested",
|
||||
// CHECK: "type": "Swift.Int",
|
||||
// CHECK: "valueKind": "RawLiteral",
|
||||
// CHECK: "value": "8"
|
||||
|
||||
@@ -43,8 +43,14 @@ public struct AddExtensionMacro: ExtensionMacro {
|
||||
) throws -> [ExtensionDeclSyntax] {
|
||||
let typeName = declaration.declGroupName
|
||||
return protocols.map {
|
||||
("extension \(typeName): \($0) { }" as DeclSyntax)
|
||||
.cast(ExtensionDeclSyntax.self)
|
||||
("""
|
||||
extension \(typeName): \($0) {
|
||||
struct _Extension_\($0): \($0) {
|
||||
var nested = 8
|
||||
}
|
||||
}
|
||||
""" as DeclSyntax)
|
||||
.cast(ExtensionDeclSyntax.self)
|
||||
} + [
|
||||
("""
|
||||
extension \(typeName) {
|
||||
|
||||
Reference in New Issue
Block a user