diff --git a/Sources/SyntaxSparrow/Internal/Resolvers/Declaration/VariableSemanticsResolver.swift b/Sources/SyntaxSparrow/Internal/Resolvers/Declaration/VariableSemanticsResolver.swift index 8b536890..36538de7 100644 --- a/Sources/SyntaxSparrow/Internal/Resolvers/Declaration/VariableSemanticsResolver.swift +++ b/Sources/SyntaxSparrow/Internal/Resolvers/Declaration/VariableSemanticsResolver.swift @@ -80,7 +80,7 @@ struct VariableSemanticsResolver: SemanticsResolving { func resolveHasSetter() -> Bool { // If setter exists in accessors can return true - let hasSetterAccessor = resolveAccessors().contains(where: { $0.kind == .set || $0.kind == .willSet }) + let hasSetterAccessor = resolveAccessors().contains(where: { $0.kind == .set || $0.kind == .willSet || $0.kind == .didSet }) if hasSetterAccessor { return true } diff --git a/Tests/SyntaxSparrowTests/Declarations/VariableTests.swift b/Tests/SyntaxSparrowTests/Declarations/VariableTests.swift index 391291cc..1285ae2f 100644 --- a/Tests/SyntaxSparrowTests/Declarations/VariableTests.swift +++ b/Tests/SyntaxSparrowTests/Declarations/VariableTests.swift @@ -195,6 +195,52 @@ final class VariableTests: XCTestCase { XCTAssertEqual(protocolOne.variables[2].accessors.map(\.kind), []) } + func test_variable_hasSetterHelper_nested_willResolveExpectedValues() { + let source = #""" + protocol Example { + var name: String { get } + var name: String { get set } + } + + class Example { + let name: String = "test" + var nameTwo: String = "test" + var nameThree: String = "test" { + didSet {} + } + } + + struct Example { + let name: String = "test" + var nameTwo: String = "test" + var nameThree: String = "test" { + didSet {} + } + } + """# + instanceUnderTest.updateToSource(source) + XCTAssertTrue(instanceUnderTest.isStale) + instanceUnderTest.collectChildren() + XCTAssertFalse(instanceUnderTest.isStale) + // Protocols + var variables = instanceUnderTest.protocols[0].variables + XCTAssertEqual(variables.count, 2) + XCTAssertFalse(variables[0].hasSetter) + XCTAssertTrue(variables[1].hasSetter) + // Class + variables = instanceUnderTest.classes[0].variables + XCTAssertEqual(variables.count, 3) + XCTAssertFalse(variables[0].hasSetter) + XCTAssertTrue(variables[1].hasSetter) + XCTAssertTrue(variables[2].hasSetter) + // Struct + variables = instanceUnderTest.structures[0].variables + XCTAssertEqual(variables.count, 3) + XCTAssertFalse(variables[0].hasSetter) + XCTAssertTrue(variables[1].hasSetter) + XCTAssertTrue(variables[2].hasSetter) + } + func test_variable_hasSetterHelper_willResolveExpectedValues() { let source = #""" var name: String {