Skip to content

Make the @Observable macro class only #67033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

natecook1000
Copy link
Member

This removes the ability for the Observable macro to apply to structs, and adds diagnostic tests for the three disallowed declaration kinds. It also adds Codable and Hashable conformance to the ObservationRegistrar type, in order to smooth the future direction of @Observable support for structs.

These conformances enable automatic Codable synthesis for Observable
types, and smooth the runway for structs being supported by the
Observable macro in the future.
This removes the ability for the Observable macro to apply to structs,
and adds diagnostic tests for the three disallowed declaration kinds.
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test

1 similar comment
@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000
Copy link
Member Author

@swift-ci Please test macOS platform

(unrelated failure last time)

@natecook1000
Copy link
Member Author

@swift-ci Please test macOS platform

@natecook1000
Copy link
Member Author

@swift-ci Please test and merge

@natecook1000
Copy link
Member Author

@swift-ci Please test macOS platform

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 40a7396 into swiftlang:main Jul 6, 2023
natecook1000 added a commit to natecook1000/swift that referenced this pull request Jul 10, 2023
* Make ObservationRegistrar Codable/Hashable

These conformances enable automatic Codable synthesis for Observable
types, and smooth the runway for structs being supported by the
Observable macro in the future.

* Limit Observable macro to classes

This removes the ability for the Observable macro to apply to structs,
and adds diagnostic tests for the three disallowed declaration kinds.
natecook1000 added a commit that referenced this pull request Jul 11, 2023
* Make the `@Observable` macro class only (#67033)

* Make ObservationRegistrar Codable/Hashable

These conformances enable automatic Codable synthesis for Observable
types, and smooth the runway for structs being supported by the
Observable macro in the future.

* Limit Observable macro to classes

This removes the ability for the Observable macro to apply to structs,
and adds diagnostic tests for the three disallowed declaration kinds.

* [Observation] Switch `Observable` to be a non-marker protocol (#66993)

With support for redundant conformance declarations via macros,
the `Observable` protocol can be a non-marker protocol, which
provides more flexibility for evolution in the future.

rdar://111463883

This change also switches to the new ExtensionMacro protocol,
the requirement for which includes information about whether the
conformance to the Observable protocol has already been added, either
in the declaration or in a superclass to the macro-attributed type.
This allows the @observable macro to be applied to subclasses of
observable types without redundant-conformance errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants