From b851897dc7977c703973b3a0716d79a199051e9f Mon Sep 17 00:00:00 2001 From: Sergey Erokhin <32620370+till0xff@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:06:10 +0300 Subject: [PATCH] Fix protocol inheritance (#1383) --- SourceryRuntime/Sources/Common/Composer/Composer.swift | 2 +- .../Sources/SourceryRuntime.content.generated.swift | 2 +- SourceryTests/Parsing/ComposerSpec.swift | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/SourceryRuntime/Sources/Common/Composer/Composer.swift b/SourceryRuntime/Sources/Common/Composer/Composer.swift index 9cafbace4..43aa59d65 100644 --- a/SourceryRuntime/Sources/Common/Composer/Composer.swift +++ b/SourceryRuntime/Sources/Common/Composer/Composer.swift @@ -272,7 +272,7 @@ public enum Composer { if baseType is Class { type.inherits[baseType.name] = baseType } else if let `protocol` = baseType as? SourceryProtocol { - type.implements[baseType.name] = baseType + type.implements[baseType.globalName] = baseType if let extendingProtocol = type as? SourceryProtocol { `protocol`.associatedTypes.forEach { if extendingProtocol.associatedTypes[$0.key] == nil { diff --git a/SourcerySwift/Sources/SourceryRuntime.content.generated.swift b/SourcerySwift/Sources/SourceryRuntime.content.generated.swift index 28f02a73a..e33d9bdc1 100644 --- a/SourcerySwift/Sources/SourceryRuntime.content.generated.swift +++ b/SourcerySwift/Sources/SourceryRuntime.content.generated.swift @@ -1005,7 +1005,7 @@ public enum Composer { if baseType is Class { type.inherits[baseType.name] = baseType } else if let `protocol` = baseType as? SourceryProtocol { - type.implements[baseType.name] = baseType + type.implements[baseType.globalName] = baseType if let extendingProtocol = type as? SourceryProtocol { `protocol`.associatedTypes.forEach { if extendingProtocol.associatedTypes[$0.key] == nil { diff --git a/SourceryTests/Parsing/ComposerSpec.swift b/SourceryTests/Parsing/ComposerSpec.swift index 2bae5b5bb..781be341c 100644 --- a/SourceryTests/Parsing/ComposerSpec.swift +++ b/SourceryTests/Parsing/ComposerSpec.swift @@ -2451,6 +2451,15 @@ class ParserComposerSpec: QuickSpec { } } + it("resolves inherited properties") { + let types = parseModules( + ("A", "protocol Foo { var a: Int { get } }"), + ("B", "protocol Foo { var b: Int { get } }"), + ("C", "import A; import B; protocol Foo: A.Foo, B.Foo { var c: Int { get } }")) + + expect(types.last?.allVariables.map(\.name).sorted()).to(equal(["a", "b", "c"])) + } + it("resolves types properly") { let types = parseModules( ("Mod1", "protocol Foo { func foo1() }"),