Skip to content

Commit

Permalink
Enabled lookup for generic type information in arrays (#1346)
Browse files Browse the repository at this point in the history
* Enabled lookup for generic type information in arrays

* Added unit test
  • Loading branch information
art-divin authored Jun 22, 2024
1 parent 36e9822 commit 990b247
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SourceryRuntime/Sources/Common/AST/TypeName/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class ArrayType: NSObject, SourceryModel, Diffable {
/// Returns array as generic type
public var asGeneric: GenericType {
GenericType(name: "Array", typeParameters: [
.init(typeName: elementTypeName)
.init(typeName: elementTypeName, type: elementType)
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ internal struct ParserResultsComposed {
if let array = lookupName.array {
array.elementType = resolveTypeWithName(array.elementTypeName)

if array.elementTypeName.actualTypeName != nil || retrievedName != nil {
if array.elementTypeName.actualTypeName != nil || retrievedName != nil || array.elementType != nil {
let array = ArrayType(name: array.name, elementTypeName: array.elementTypeName, elementType: array.elementType)
array.elementTypeName = array.elementTypeName.actualTypeName ?? array.elementTypeName
array.elementTypeName.actualTypeName = nil
Expand Down
28 changes: 28 additions & 0 deletions SourceryTests/Models/ArrayTypeSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Quick
import Nimble
#if SWIFT_PACKAGE
@testable import SourceryLib
#else
@testable import Sourcery
#endif
@testable import SourceryRuntime

class ArrayTypeSpec: QuickSpec {
override func spec() {
describe("Array") {
var sut: ArrayType?

beforeEach {
sut = ArrayType(name: "Foo", elementTypeName: TypeName(name: "Foo"), elementType: Type(name: "Bar"))
}

afterEach {
sut = nil
}

it("preserves element type for generic") {
expect(sut?.asGeneric.typeParameters.first?.type).toNot(beNil())
}
}
}
}

0 comments on commit 990b247

Please sign in to comment.