File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Sources/SyntaxSparrow/Internal/Resolvers/Declaration
Tests/SyntaxSparrowTests/Declarations Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,9 @@ struct VariableSemanticsResolver: SemanticsResolving {
116116 // Resolver accessors for assessment
117117 let accessors = resolveAccessors ( )
118118 let accessorKinds = accessors. compactMap ( \. kind)
119+ // Only getter accessors mean that there is no setters
120+ guard accessorKinds != [ . get] else { return false }
121+ // General setter check
119122 let hasSetterAccessor = accessorKinds. contains ( where: { [ . set, . willSet, . didSet] . contains ( $0) } )
120123 let hasEffectGetter = accessors. contains ( where: {
121124 let hasSpecifier = ( $0. effectSpecifiers? . throwsSpecifier != nil || $0. effectSpecifiers? . asyncSpecifier != nil )
@@ -125,7 +128,7 @@ struct VariableSemanticsResolver: SemanticsResolving {
125128 guard !hasEffectGetter else { return false }
126129 // If setter exists in accessors can return true (usually protocol context or manually written will/did/set accessor).
127130 if hasSetterAccessor { return true }
128- // If no accessors, but a direct return/code block, can assume there is no setter
131+ // If no accessors, but a direct return/code block, can assume there is no setter. (computed var)
129132 if accessors. isEmpty, resolveHasCodeBlockItems ( ) { return false }
130133 // Otherwise if the keyword is not `let` (immutable)
131134 guard resolveKeyword ( ) != " let " else { return false }
Original file line number Diff line number Diff line change @@ -66,6 +66,24 @@ final class VariableTests: XCTestCase {
6666 XCTAssertFalse ( variable. hasSetter)
6767 }
6868
69+ func test_variable_mutable_onlyGetter_willReturnFalseForHasSetter( ) {
70+ let source = #"""
71+ var name: String {
72+ get { "test" }
73+ }
74+ var other: String {
75+ "test"
76+ }
77+ """#
78+ instanceUnderTest. updateToSource ( source)
79+ XCTAssertTrue ( instanceUnderTest. isStale)
80+ instanceUnderTest. collectChildren ( )
81+ XCTAssertFalse ( instanceUnderTest. isStale)
82+ XCTAssertEqual ( instanceUnderTest. variables. count, 2 )
83+ XCTAssertFalse ( instanceUnderTest. variables [ 0 ] . hasSetter)
84+ XCTAssertFalse ( instanceUnderTest. variables [ 1 ] . hasSetter)
85+ }
86+
6987 func test_variable_multiplePatternBindings_willResolveExpectedValues( ) {
7088 let source = #"""
7189 var firstName, lastName: String
@@ -297,7 +315,7 @@ final class VariableTests: XCTestCase {
297315 XCTAssertFalse ( instanceUnderTest. variables [ 4 ] . isComputed)
298316 XCTAssertTrue ( instanceUnderTest. variables [ 5 ] . isComputed)
299317 XCTAssertTrue ( instanceUnderTest. variables [ 6 ] . isComputed)
300- XCTAssertFalse ( instanceUnderTest. variables [ 7 ] . isComputed)
318+ XCTAssertTrue ( instanceUnderTest. variables [ 7 ] . isComputed)
301319 }
302320
303321 func test_variable_hasSetterHelper_willResolveExpectedValues( ) {
You can’t perform that action at this time.
0 commit comments