diff --git a/include/swift/AST/ProtocolConformance.h b/include/swift/AST/ProtocolConformance.h index 5742f1fd6ce78..0d1d726c02f04 100644 --- a/include/swift/AST/ProtocolConformance.h +++ b/include/swift/AST/ProtocolConformance.h @@ -606,7 +606,7 @@ class InheritedProtocolConformance : public ProtocolConformance, /// Get the declaration context that contains the conforming extension or /// nominal type declaration. DeclContext *getDeclContext() const { - return InheritedConformance->getDeclContext(); + return getType()->getClassOrBoundGenericClass(); } /// Retrieve the state of this conformance. diff --git a/test/SILOptimizer/specialize_inherited.sil b/test/SILOptimizer/specialize_inherited.sil index 73f8b26bed01e..e702a399c1fe3 100644 --- a/test/SILOptimizer/specialize_inherited.sil +++ b/test/SILOptimizer/specialize_inherited.sil @@ -27,7 +27,7 @@ bb0(%0 : $Int, %1 : $Int): // CHECK: [[STACK:%[0-9]+]] = alloc_stack $MMString %37 = alloc_stack $MMString - // CHECK: [[ID:%[0-9]+]] = function_ref @_TTSg5C7inherit8MMStringCS_8MMObjects8HashableS__GSQCS_6MMFont___callee : $@convention(method) (@in MMString, Int, @owned MMStorage>) -> Bool + // CHECK: [[ID:%[0-9]+]] = function_ref @_TTSg5C7inherit8MMStringS0_s8HashableS__GSQCS_6MMFont___callee : $@convention(method) (@in MMString, Int, @owned MMStorage>) -> Bool %34 = function_ref @callee : $@convention(method) <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (@in τ_0_0, Int, @owned MMStorage<τ_0_0, τ_0_1>) -> Bool // CHECK: apply [[ID]]([[STACK]], %1, %{{[0-9]+}}) : $@convention(method) (@in MMString, Int, @owned MMStorage>) -> Bool %45 = apply %34(%37, %1, %14) : $@convention(method) <τ_0_0, τ_0_1 where τ_0_0 : Hashable> (@in τ_0_0, Int, @owned MMStorage<τ_0_0, τ_0_1>) -> Bool @@ -36,7 +36,7 @@ bb0(%0 : $Int, %1 : $Int): return %14 : $MMStorage> } -// CHECK-LABEL: @_TTSg5C7inherit8MMStringCS_8MMObjects8HashableS__GSQCS_6MMFont___callee : $@convention(method) (@in MMString, Int, @owned MMStorage>) -> Bool { +// CHECK-LABEL: @_TTSg5C7inherit8MMStringS0_s8HashableS__GSQCS_6MMFont___callee : $@convention(method) (@in MMString, Int, @owned MMStorage>) -> Bool { // CHECK: [[META:%[0-9]+]] = metatype $@thick MMString.Type // CHECK: [[ID3:%[0-9]+]] = witness_method $MMObject, #Equatable."=="!1 : // CHECK: [[STACK2:%[0-9]+]] = alloc_stack $MMString diff --git a/test/decl/class/Inputs/inheritance_protocol_multi_module_2.swift b/test/decl/class/Inputs/inheritance_protocol_multi_module_2.swift new file mode 100644 index 0000000000000..666a9a378377d --- /dev/null +++ b/test/decl/class/Inputs/inheritance_protocol_multi_module_2.swift @@ -0,0 +1,16 @@ +import Mod + +class ClassLevel3: ClassLevel2 { + override init() { + super.init() + } +} + +public func createClassLevel3() -> MyProtocol { + return ClassLevel3() +} + +public func createClassLevel3() -> MyProtocol2 { + return ClassLevel3() +} + diff --git a/test/decl/class/inheritance_protocol_multi_module.swift b/test/decl/class/inheritance_protocol_multi_module.swift new file mode 100644 index 0000000000000..d4004daa844f6 --- /dev/null +++ b/test/decl/class/inheritance_protocol_multi_module.swift @@ -0,0 +1,15 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: %target-swift-frontend -emit-module-path %t/Mod.swiftmodule -module-name Mod %s +// RUN: %target-swift-frontend -parse -verify -I %t %S/Inputs/inheritance_protocol_multi_module_2.swift + +/* module Mod */ + +public protocol MyProtocol {} +public protocol MyProtocol2 {} +public class ClassLevel1: MyProtocol { + public init() {} +} +public class ClassLevel2: ClassLevel1, MyProtocol2 { + public override init () {} +}