Skip to content

Commit 533464e

Browse files
committed
[Macros] Add test for macro expansion printing
* Macro expanded member decls in .swiftinterface (rdar://117374821) * cursor-info on a decl with peer macro attribute (rdar://117374966) (cherry picked from commit 55144fb)
1 parent 15a45e2 commit 533464e

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ public struct AddPeerStoredPropertyMacro: PeerMacro, Sendable {
19001900
return [
19011901
"""
19021902
1903-
private var _foo: Int = 100
1903+
public var _foo: Int = 100
19041904
"""
19051905
]
19061906
}

test/ModuleInterface/macros.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,35 @@ macro structWithUnqualifiedLookup() = #externalMacro(module: "MacroDefinition",
6464

6565
let world = 17
6666

67-
// CHECK-NOT: structWithUnqualifiedLookup
6867
public
6968
#structWithUnqualifiedLookup
70-
69+
// CHECK-NOT: structWithUnqualifiedLookup
70+
// CHECK-NOT: struct StructWithUnqualifiedLookup
7171
// CHECK: struct StructWithUnqualifiedLookup
72+
// CHECK-NOT: struct StructWithUnqualifiedLookup
73+
74+
@attached(peer, names: named(_foo))
75+
macro AddPeerStoredProperty() = #externalMacro(module: "MacroDefinition", type: "AddPeerStoredPropertyMacro")
76+
77+
@AddPeerStoredProperty
78+
public var test: Int = 10
79+
// CHECK: var test
80+
// CHECK-NOT: var _foo
81+
// CHECK: var _foo
82+
// CHECK-NOT: var _foo
83+
84+
// CHECK: struct TestStruct {
85+
public struct TestStruct {
86+
public #structWithUnqualifiedLookup
87+
// CHECK-NOT: structWithUnqualifiedLookup
88+
// CHECK-NOT: struct StructWithUnqualifiedLookup
89+
// CHECK: struct StructWithUnqualifiedLookup
90+
// CHECK-NOT: struct StructWithUnqualifiedLookup
91+
92+
@AddPeerStoredProperty
93+
public var test: Int = 10
94+
// CHECK: var test
95+
// CHECK-NOT: var _foo
96+
// CHECK: var _foo
97+
// CHECK-NOT: var _foo
98+
}

test/SourceKit/Macros/macro_basic.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
6060
@freestanding(expression) macro assert(_: String) = #externalMacro(module: "MacroDefinition", type: "AssertMacro")
6161
#assert("foobar")
6262

63+
@attached(peer, names: named(_foo))
64+
macro AddPeerStoredProperty() = #externalMacro(module: "MacroDefinition", type: "AddPeerStoredPropertyMacro")
65+
struct S5 {
66+
@AddPeerStoredProperty
67+
var test: Int = 10
68+
}
69+
6370
// REQUIRES: swift_swift_parser, executable_test, shell
6471

6572
// RUN: %empty-directory(%t)
@@ -281,3 +288,8 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
281288
//##-- Expansion on "fails to typecheck" macro expression
282289
// RUN: %sourcekitd-test -req=refactoring.expand.macro -pos=61:2 %s -- ${COMPILER_ARGS[@]} | %FileCheck -check-prefix=ERRONEOUS_EXPAND %s
283290
// ERRONEOUS_EXPAND: 61:1-61:18 (@__swiftmacro_{{.+}}.swift) "assert("foobar")"
291+
292+
//##-- Cursor-info on a decl where a peer macro attached.
293+
// RUN: %sourcekitd-test -req=cursor -pos=67:7 %s -- ${COMPILER_ARGS[@]} | %FileCheck -check-prefix=CURSOR_ON_DECL_WITH_PEER %s
294+
// CURSOR_ON_DECL_WITH_PEER: <decl.var.instance><syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>test</decl.name>: <decl.var.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.type></decl.var.instance>
295+
// CURSOR_ON_DECL_WITH_PEER-NOT: _foo

0 commit comments

Comments
 (0)