Skip to content

Commit 2f3b51a

Browse files
authored
Merge pull request #63370 from DougGregor/accessor-member-macro-fixes
2 parents 8f87047 + d06e84d commit 2f3b51a

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/Sema/TypeCheckMacros.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,24 @@ void swift::expandAccessors(
938938
// Trigger parsing of the sequence of accessor declarations. This has the
939939
// side effect of registering those accessor declarations with the storage
940940
// declaration, so there is nothing further to do.
941-
(void)macroSourceFile->getTopLevelItems();
941+
for (auto decl : macroSourceFile->getTopLevelItems()) {
942+
auto accessor = dyn_cast_or_null<AccessorDecl>(decl.dyn_cast<Decl *>());
943+
if (!accessor)
944+
continue;
945+
946+
if (accessor->isObservingAccessor())
947+
continue;
948+
949+
// If any non-observing accessor was added, remove the initializer if
950+
// there is one.
951+
if (auto var = dyn_cast<VarDecl>(storage)) {
952+
if (auto binding = var->getParentPatternBinding()) {
953+
unsigned index = binding->getPatternEntryIndexForVarDecl(var);
954+
binding->setInit(index, nullptr);
955+
break;
956+
}
957+
}
958+
}
942959
}
943960

944961
bool swift::expandAttributes(CustomAttr *attr, MacroDecl *macro, Decl *member) {

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,10 +2657,10 @@ getActualMacroRole(uint8_t context) {
26572657
CASE(Declaration)
26582658
CASE(Accessor)
26592659
CASE(MemberAttribute)
2660+
CASE(Member)
26602661
#undef CASE
2661-
default:
2662-
return None;
26632662
}
2663+
return None;
26642664
}
26652665

26662666
static Optional<swift::MacroIntroducedDeclNameKind>

test/Macros/accessor_macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %target-build-swift -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
33

44
// First check for no errors.
5-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s
5+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir
66

77
// Check that the expansion buffer are as expected.
88
// RUN: %target-swift-frontend -typecheck -enable-experimental-feature Macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -dump-macro-expansions > %t/expansions-dump.txt 2>&1
@@ -53,7 +53,7 @@ struct MyStruct {
5353
// CHECK-DUMP: }
5454

5555
@myPropertyWrapper
56-
var birthDate: Date?
56+
var birthDate: Date? = nil
5757
// CHECK-DUMP: macro:birthDate@myPropertyWrapper
5858
// CHECK-DUMP: get {
5959
// CHECK-DUMP: _birthDate.wrappedValue

0 commit comments

Comments
 (0)