Skip to content
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

Fixed missing attributes in optional closure type name #1237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension TypeName {
} else if let typeIdentifier = node.as(OptionalTypeSyntax.self) {
let type = TypeName(typeIdentifier.wrappedType)
let needsWrapping = type.isClosure || type.isProtocolComposition
self.init(name: needsWrapping ? "(\(type.name))" : type.name,
self.init(name: needsWrapping ? "(\(type.asSource))" : type.name,
isOptional: true,
isImplicitlyUnwrappedOptional: false,
tuple: type.tuple,
Expand All @@ -78,7 +78,7 @@ extension TypeName {
} else if let typeIdentifier = node.as(ImplicitlyUnwrappedOptionalTypeSyntax.self) {
let type = TypeName(typeIdentifier.wrappedType)
let needsWrapping = type.isClosure || type.isProtocolComposition
self.init(name: needsWrapping ? "(\(type.name))" : type.name,
self.init(name: needsWrapping ? "(\(type.asSource))" : type.name,
isOptional: false,
isImplicitlyUnwrappedOptional: true,
tuple: type.tuple,
Expand Down
18 changes: 18 additions & 0 deletions SourceryTests/Parsing/FileParser_TypeNameSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ class TypeNameSpec: QuickSpec {
expect(typeName("@escaping @autoclosure () -> String").description).to(equal("@autoclosure @escaping () -> String"))
}
}

context("given optional closure type with attributes") {
it("keeps attributes in unwrappedTypeName") {
expect(typeName("(@MainActor @Sendable (Int) -> Void)?").unwrappedTypeName).to(equal("(@MainActor @Sendable (Int) -> Void)"))
}
it("keeps attributes in name") {
expect(typeName("(@MainActor @Sendable (Int) -> Void)?").name).to(equal("(@MainActor @Sendable (Int) -> Void)?"))
}
}

context("given implicitly unwrapped optional closure type with attributes") {
it("keeps attributes in unwrappedTypeName") {
expect(typeName("(@MainActor @Sendable (Int) -> Void)!").unwrappedTypeName).to(equal("(@MainActor @Sendable (Int) -> Void)"))
}
it("keeps attributes in name") {
expect(typeName("(@MainActor @Sendable (Int) -> Void)!").name).to(equal("(@MainActor @Sendable (Int) -> Void)!"))
}
}
}
}
}