File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -908,6 +908,10 @@ swift::expandFreestandingDeclarationMacro(MacroExpansionDecl *med) {
908
908
/* parsingOpts=*/ {}, /* isPrimary=*/ false );
909
909
macroSourceFile->setImports (sourceFile->getImports ());
910
910
911
+ validateMacroExpansion (macroSourceFile, macro,
912
+ /* attachedTo*/ nullptr ,
913
+ MacroRole::Declaration);
914
+
911
915
PrettyStackTraceDecl debugStack (
912
916
" type checking expanded declaration macro" , med);
913
917
Original file line number Diff line number Diff line change @@ -764,7 +764,7 @@ public struct AddCompletionHandler: PeerMacro {
764
764
}
765
765
}
766
766
767
- public struct InvalidMacro : PeerMacro {
767
+ public struct InvalidMacro : PeerMacro , DeclarationMacro {
768
768
public static func expansion(
769
769
of node: AttributeSyntax ,
770
770
providingPeersOf declaration: some DeclSyntaxProtocol ,
@@ -794,6 +794,15 @@ public struct InvalidMacro: PeerMacro {
794
794
" typealias _FileReferenceLiteralType = Void " ,
795
795
]
796
796
}
797
+
798
+ public static func expansion(
799
+ of node: some FreestandingMacroExpansionSyntax ,
800
+ in context: some MacroExpansionContext
801
+ ) throws -> [ DeclSyntax ] {
802
+ return [
803
+ " var value: Int "
804
+ ]
805
+ }
797
806
}
798
807
799
808
public struct WrapInType : PeerMacro {
Original file line number Diff line number Diff line change 27
27
// REQUIRES: OS=macosx
28
28
29
29
#if TEST_DIAGNOSTICS
30
+ @freestanding ( declaration)
31
+ macro NotCovered( ) = #externalMacro( module: " MacroDefinition " , type: " InvalidMacro " )
32
+
33
+ struct MemberNotCovered {
34
+ #NotCovered
35
+ // expected-note@-1 {{in expansion of macro 'NotCovered' here}}
36
+
37
+ // CHECK-DIAGS: error: declaration name 'value' is not covered by macro 'NotCovered'
38
+ // CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser16MemberNotCoveredV0dE0fMf0_.swift
39
+ // CHECK-DIAGS: var value: Int
40
+ // CHECK-DIAGS: END CONTENTS OF FILE
41
+ }
42
+
30
43
@attached ( peer)
31
44
macro Invalid( ) = #externalMacro( module: " MacroDefinition " , type: " InvalidMacro " )
32
45
You can’t perform that action at this time.
0 commit comments