Skip to content

Commit

Permalink
Initialise Subscript's returnTypeName with TypeSyntax, not String (#1250
Browse files Browse the repository at this point in the history
)
  • Loading branch information
igor-savelev-bumble authored Jan 6, 2024
1 parent c7b57bc commit b62a8fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension Subscript {

self.init(
parameters: node.indices.parameterList.map { MethodParameter($0, annotationsParser: annotationsParser) },
returnTypeName: TypeName(node.result.returnType.description.trimmed),
returnTypeName: TypeName(node.result.returnType),
accessLevel: (read: readAccess, write: isWritable ? writeAccess : .none),
isAsync: hadAsync,
throws: hadThrowable,
Expand Down
17 changes: 16 additions & 1 deletion SourceryTests/Parsing/FileParser_SubscriptsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class FileParserSubscriptsSpec: QuickSpec {
expect(subscripts?[2].genericRequirements.first?.relationshipSyntax).to(equal(":"))
expect(subscripts?[2].genericRequirements.first?.rightType.typeName.name).to(equal("Cancellable"))
}

it("extracts async and throws") {
let subscripts = parse("""
protocol Subscript: AnyObject {
Expand All @@ -135,6 +135,21 @@ class FileParserSubscriptsSpec: QuickSpec {
expect(subscripts?[1].throws).to(beTrue())
expect(subscripts?[2].throws).to(beTrue())
}

it("extracts optional return type") {
let subscripts = parse("""
protocol Subscript: AnyObject {
subscript(arg1: Int) -> Int? { get set }
subscript(arg2: Int) -> Int! { get }
}
""").first?.subscripts

expect(subscripts?[0].returnTypeName.name).to(equal("Int?"))
expect(subscripts?[0].returnTypeName.unwrappedTypeName).to(equal("Int"))

expect(subscripts?[1].returnTypeName.name).to(equal("Int!"))
expect(subscripts?[1].returnTypeName.unwrappedTypeName).to(equal("Int"))
}
}
}
}
Expand Down

0 comments on commit b62a8fc

Please sign in to comment.