From 5029e6f5cba879eadd4c15fff8854620a6f21b6a Mon Sep 17 00:00:00 2001 From: Paul Taykalo Date: Sat, 20 Jul 2024 23:49:08 +0300 Subject: [PATCH] Fix multi-threaded access when generic types are generated --- .../Sources/Common/Composer/Composer.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SourceryRuntime/Sources/Common/Composer/Composer.swift b/SourceryRuntime/Sources/Common/Composer/Composer.swift index 9cafbace4..c12a64b07 100644 --- a/SourceryRuntime/Sources/Common/Composer/Composer.swift +++ b/SourceryRuntime/Sources/Common/Composer/Composer.swift @@ -24,12 +24,21 @@ public enum Composer { public static func uniqueTypesAndFunctions(_ parserResult: FileParserResult, serial: Bool = false) -> (types: [Type], functions: [SourceryMethod], typealiases: [Typealias]) { let composed = ParserResultsComposed(parserResult: parserResult) + let resolveTypeLock = NSLock() let resolveType = { (typeName: TypeName, containingType: Type?) -> Type? in - composed.resolveType(typeName: typeName, containingType: containingType) + var result: Type? + resolveTypeLock.lock() + result = composed.resolveType(typeName: typeName, containingType: containingType) + resolveTypeLock.unlock() + return result } let methodResolveType = { (typeName: TypeName, containingType: Type?, method: Method) -> Type? in - composed.resolveType(typeName: typeName, containingType: containingType, method: method) + var result: Type? + resolveTypeLock.lock() + result = composed.resolveType(typeName: typeName, containingType: containingType, method: method) + resolveTypeLock.unlock() + return result } let processType = { (type: Type) in