mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: Also respect @_originallyDefinedIn in TypeDecl::compare()
If a protocol was moved from one module to another, we need to continue using the old module name when comparing it against other protocols.
This commit is contained in:
@@ -5439,6 +5439,13 @@ int TypeDecl::compare(const TypeDecl *type1, const TypeDecl *type2) {
|
||||
// of the ABI, and so we must take care to get the correct module
|
||||
// name for the comparison.
|
||||
auto getModuleNameForOrder = [&](const TypeDecl *decl) -> StringRef {
|
||||
// Respect @_originallyDefinedIn on the type itself, so that
|
||||
// moving a protocol across modules does not change its
|
||||
// position in the order.
|
||||
auto alternateName = decl->getAlternateModuleName();
|
||||
if (!alternateName.empty())
|
||||
return alternateName;
|
||||
|
||||
// This used to just call getName(), which caused accidental ABI breaks
|
||||
// when a module is imported under different aliases.
|
||||
//
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// RUN: %target-swift-emit-silgen %s -module-name main | %FileCheck %s
|
||||
|
||||
// REQUIRES: OS=macosx
|
||||
|
||||
@_originallyDefinedIn(module: "AnimalKit", macOS 10.10)
|
||||
@available(macOS 10.9, *)
|
||||
public protocol Ungulate {}
|
||||
|
||||
@_originallyDefinedIn(module: "HorseKit", macOS 10.10)
|
||||
@available(macOS 10.9, *)
|
||||
public protocol Horse {}
|
||||
|
||||
// CHECK-LABEL: sil [ossa] @$s4main39requirementOrderWithOriginallyDefinedInyyx9AnimalKit8UngulateRz05HorseI00K0RzlF : $@convention(thin) <T where T : Ungulate, T : Horse> (@in_guaranteed T) -> () {
|
||||
public func requirementOrderWithOriginallyDefinedIn<T: Ungulate & Horse>(_: T) {}
|
||||
Reference in New Issue
Block a user