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 @@ -913,6 +913,10 @@ swift::expandFreestandingMacro(MacroExpansionDecl *med) {
913
913
/* parsingOpts=*/ {}, /* isPrimary=*/ false );
914
914
macroSourceFile->setImports (sourceFile->getImports ());
915
915
916
+ validateMacroExpansion (macroSourceFile, macro,
917
+ /* attachedTo*/ nullptr ,
918
+ MacroRole::Declaration);
919
+
916
920
PrettyStackTraceDecl debugStack (
917
921
" type checking expanded declaration macro" , med);
918
922
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 31
31
// REQUIRES: OS=macosx
32
32
33
33
#if TEST_DIAGNOSTICS
34
+ @freestanding ( declaration)
35
+ macro NotCovered( ) = #externalMacro( module: " MacroDefinition " , type: " InvalidMacro " )
36
+
37
+ struct MemberNotCovered {
38
+ #NotCovered
39
+ // expected-note@-1 {{in expansion of macro 'NotCovered' here}}
40
+
41
+ // CHECK-DIAGS: error: declaration name 'value' is not covered by macro 'NotCovered'
42
+ // CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser16MemberNotCoveredV0dE0fMf0_.swift
43
+ // CHECK-DIAGS: var value: Int
44
+ // CHECK-DIAGS: END CONTENTS OF FILE
45
+ }
46
+
34
47
@attached ( peer)
35
48
macro Invalid( ) = #externalMacro( module: " MacroDefinition " , type: " InvalidMacro " )
36
49
You can’t perform that action at this time.
0 commit comments