diff --git a/Sources/SwiftRefactor/ConvertStoredPropertyToComputed.swift b/Sources/SwiftRefactor/ConvertStoredPropertyToComputed.swift index 179b6c5b600..6ff6d8d4c1a 100644 --- a/Sources/SwiftRefactor/ConvertStoredPropertyToComputed.swift +++ b/Sources/SwiftRefactor/ConvertStoredPropertyToComputed.swift @@ -69,15 +69,20 @@ public struct ConvertStoredPropertyToComputed: SyntaxRefactoringProvider { if let existingType = binding.typeAnnotation { typeAnnotation = existingType } else if let providedType = context.type { - typeAnnotation = TypeAnnotationSyntax(type: providedType) + typeAnnotation = TypeAnnotationSyntax( + colon: .colonToken(trailingTrivia: .space), + type: providedType + ) } else { typeAnnotation = TypeAnnotationSyntax( + colon: .colonToken(trailingTrivia: .space), type: TypeSyntax(stringLiteral: "<#Type#>") ) } let newBinding = binding + .with(\.pattern, binding.pattern.with(\.trailingTrivia, [])) .with(\.initializer, nil) .with(\.typeAnnotation, typeAnnotation) .with( diff --git a/Tests/SwiftRefactorTest/ConvertStoredPropertyToComputedTest.swift b/Tests/SwiftRefactorTest/ConvertStoredPropertyToComputedTest.swift index 09f084a3a0e..adf8c799392 100644 --- a/Tests/SwiftRefactorTest/ConvertStoredPropertyToComputedTest.swift +++ b/Tests/SwiftRefactorTest/ConvertStoredPropertyToComputedTest.swift @@ -297,14 +297,14 @@ final class ConvertStoredPropertyToComputedTest: XCTestCase { func testRefactoringStoredPropertyMissingTypeAnnotation() throws { let baseline: DeclSyntax = "var foo = \"abc\"" - let expected: DeclSyntax = "var foo :<#Type#>{ \"abc\" }" + let expected: DeclSyntax = "var foo: <#Type#>{ \"abc\" }" try assertRefactorConvert(baseline, expected: expected) } func testRefactoringStoredPropertyWithTypeAnnotation() throws { let baseline: DeclSyntax = "var foo = \"abc\"" - let expected: DeclSyntax = "var foo :String{ \"abc\" }" + let expected: DeclSyntax = "var foo: String{ \"abc\" }" let context = ConvertStoredPropertyToComputed.Context(type: TypeSyntax(stringLiteral: "String")) try assertRefactorConvert(baseline, expected: expected, context: context)