Skip to content

Commit

Permalink
Exclude @State and @Binding properties from assign-only property …
Browse files Browse the repository at this point in the history
…analysis. Closes #728
  • Loading branch information
ileitch committed May 19, 2024
1 parent ef8d189 commit cdb2ba9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

##### Bug Fixes

- None.
- `@State` and `@Binding` properties are now excluded from assign-only property analysis.

## 2.18.0 (2024-01-21)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ final class AssignOnlyPropertyReferenceEliminator: SourceGraphMutator {
private let configuration: Configuration
private let retainAssignOnlyPropertyTypes: [String]
private let defaultRetainedTypes = ["AnyCancellable", "Set<AnyCancellable>", "[AnyCancellable]", "NSKeyValueObservation"]
private let retainedAttributes = ["State", "Binding"]

required init(graph: SourceGraph, configuration: Configuration) {
self.graph = graph
Expand All @@ -20,6 +21,7 @@ final class AssignOnlyPropertyReferenceEliminator: SourceGraphMutator {
guard let declaredType = property.declaredType,
!retainAssignOnlyPropertyTypes.contains(declaredType),
!graph.isRetained(property),
property.attributes.isDisjoint(with: retainedAttributes),
!property.isComplexProperty,
// A protocol property can technically be assigned and never used when the protocol is used as an existential
// type, however communicating that succinctly would be very tricky, and most likely just lead to confusion.
Expand Down

0 comments on commit cdb2ba9

Please sign in to comment.