File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -882,7 +882,24 @@ void swift::expandAccessors(
882
882
// Trigger parsing of the sequence of accessor declarations. This has the
883
883
// side effect of registering those accessor declarations with the storage
884
884
// declaration, so there is nothing further to do.
885
- (void )macroSourceFile->getTopLevelItems ();
885
+ for (auto decl : macroSourceFile->getTopLevelItems ()) {
886
+ auto accessor = dyn_cast_or_null<AccessorDecl>(decl.dyn_cast <Decl *>());
887
+ if (!accessor)
888
+ continue ;
889
+
890
+ if (accessor->isObservingAccessor ())
891
+ continue ;
892
+
893
+ // If any non-observing accessor was added, remove the initializer if
894
+ // there is one.
895
+ if (auto var = dyn_cast<VarDecl>(storage)) {
896
+ if (auto binding = var->getParentPatternBinding ()) {
897
+ unsigned index = binding->getPatternEntryIndexForVarDecl (var);
898
+ binding->setInit (index, nullptr );
899
+ break ;
900
+ }
901
+ }
902
+ }
886
903
}
887
904
888
905
// FIXME: Almost entirely duplicated code from `expandAccessors`.
Original file line number Diff line number Diff line change 2
2
// 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
3
3
4
4
// 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
6
6
7
7
// Check that the expansion buffer are as expected.
8
8
// 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 {
53
53
// CHECK-DUMP: }
54
54
55
55
@myPropertyWrapper
56
- var birthDate : Date ?
56
+ var birthDate : Date ? = nil
57
57
// CHECK-DUMP: macro:birthDate@myPropertyWrapper
58
58
// CHECK-DUMP: get {
59
59
// CHECK-DUMP: _birthDate.wrappedValue
You can’t perform that action at this time.
0 commit comments