Skip to content

Commit

Permalink
Fix protocol inheritance (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
till0xff authored Nov 21, 2024
1 parent a6da5b0 commit b851897
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion SourceryRuntime/Sources/Common/Composer/Composer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions SourceryTests/Parsing/ComposerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() }"),
Expand Down

0 comments on commit b851897

Please sign in to comment.