@@ -27,7 +27,7 @@ public enum TypeDescription: Codable, Hashable, Comparable, Sendable {
27
27
/// A nested type with possible generics. e.g. Array.Element or Swift.Array<Element>
28
28
indirect case nested( name: String , parentType: TypeDescription , generics: [ TypeDescription ] )
29
29
/// A composed type. e.g. Identifiable & Equatable
30
- indirect case composition( Set < TypeDescription > )
30
+ indirect case composition( UnorderedComparingArray < TypeDescription > )
31
31
/// An optional type. e.g. Int?
32
32
indirect case optional( TypeDescription )
33
33
/// An implicitly unwrapped optional type. e.g. Int!
@@ -201,6 +201,8 @@ public enum TypeDescription: Codable, Hashable, Comparable, Sendable {
201
201
}
202
202
}
203
203
204
+ // MARK: - TypeSyntax
205
+
204
206
extension TypeSyntax {
205
207
206
208
/// - Returns: the type description for the receiver.
@@ -225,7 +227,7 @@ extension TypeSyntax {
225
227
generics: genericTypeVisitor. genericArguments)
226
228
227
229
} else if let typeIdentifiers = CompositionTypeSyntax ( self ) {
228
- return . composition( Set ( typeIdentifiers. elements. map { $0. type. typeDescription } ) )
230
+ return . composition( UnorderedComparingArray ( typeIdentifiers. elements. map { $0. type. typeDescription } ) )
229
231
230
232
} else if let typeIdentifier = OptionalTypeSyntax ( self ) {
231
233
return . optional( typeIdentifier. wrappedType. typeDescription)
@@ -290,6 +292,8 @@ extension TypeSyntax {
290
292
}
291
293
}
292
294
295
+ // MARK: - ExprSyntax
296
+
293
297
extension ExprSyntax {
294
298
public var typeDescription : TypeDescription {
295
299
if let typeExpr = TypeExprSyntax ( self ) {
@@ -359,7 +363,7 @@ extension ExprSyntax {
359
363
}
360
364
} else if let sequenceExpr = SequenceExprSyntax ( self ) {
361
365
if sequenceExpr. elements. contains ( where: { BinaryOperatorExprSyntax ( $0) != nil } ) {
362
- return . composition( Set (
366
+ return . composition( UnorderedComparingArray (
363
367
sequenceExpr
364
368
. elements
365
369
. filter { BinaryOperatorExprSyntax ( $0) == nil }
@@ -406,6 +410,38 @@ extension ExprSyntax {
406
410
}
407
411
}
408
412
413
+ // MARK: - UnorderedComparingArray
414
+
415
+ public struct UnorderedComparingArray < Element: Codable & Hashable & Sendable > : Codable , Hashable , Sendable , Collection {
416
+
417
+ init ( _ array: [ Element ] ) {
418
+ self . array = array
419
+ set = Set ( array)
420
+ }
421
+
422
+ let array : [ Element ]
423
+ private let set : Set < Element >
424
+
425
+ public static func == ( lhs: UnorderedComparingArray , rhs: UnorderedComparingArray ) -> Bool {
426
+ lhs. set == rhs. set
427
+ }
428
+
429
+ public func makeIterator( ) -> IndexingIterator < Array < Element > > {
430
+ array. makeIterator ( )
431
+ }
432
+ public var startIndex : Int { array. startIndex }
433
+ public var endIndex : Int { array. endIndex }
434
+ public func index( after i: Int ) -> Int {
435
+ array. index ( after: i)
436
+ }
437
+
438
+ public subscript( position: Int ) -> Element {
439
+ array [ position]
440
+ }
441
+ }
442
+
443
+ // MARK: - GenericArgumentVisitor
444
+
409
445
private final class GenericArgumentVisitor : SyntaxVisitor {
410
446
411
447
private( set) var genericArguments = [ TypeDescription] ( )
0 commit comments