Skip to content

Commit

Permalink
Fix a round trip debug type failure with typealias
Browse files Browse the repository at this point in the history
When checking equality of types with existential types removed,
recursively remove existential types inside an existential type.

Fixes: swiftlang#66554
  • Loading branch information
hjyamauchi committed Jun 30, 2023
1 parent 12ebe0a commit fda6f9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ class EqualUpToClangTypes
};

static bool equalWithoutExistentialTypes(Type t1, Type t2) {
auto withoutExistentialTypes = [](Type type) -> Type {
static Type (*withoutExistentialTypes)(Type) = [](Type type) -> Type {
return type.transform([](Type type) -> Type {
if (auto existential = type->getAs<ExistentialType>())
return existential->getConstraintType();
if (auto existential = type->getAs<ExistentialType>()) {
return withoutExistentialTypes(existential->getConstraintType());
}
return type;
});
};
Expand Down
10 changes: 10 additions & 0 deletions test/IRGen/round-trip-debug-types-typealias.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-build-swift -g %s

// https://github.com/apple/swift/issues/66554
// IRGenDebugInfo type reconstruction crash because existential types
// inside typealias are not taken into account when comparing type
// equality

protocol Protocol<T> { associatedtype T }
typealias AnyProtocol<T> = any Protocol<T>
let crash: AnyProtocol<Any?>

0 comments on commit fda6f9b

Please sign in to comment.