Skip to content

Commit bbe3aa7

Browse files
committed
[AST] Improve canonicalization using dependent member types.
When substituting type parameters to compute a canonical type within a given generic context, also handle the case where the type parameter is directly known to be a concrete type. The type checker won’t do this, but SourceKit does. Fixes a regression in SourceKit/DocSupport/doc_stdlib.swift.
1 parent a2a663c commit bbe3aa7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/Types.h"
2525
#include "swift/Basic/STLExtras.h"
2626
#include <functional>
27+
#include "GenericSignatureBuilderImpl.h"
2728

2829
using namespace swift;
2930

@@ -667,11 +668,17 @@ CanType GenericSignature::getCanonicalTypeInContext(Type type,
667668
!isa<DependentMemberType>(component))
668669
return None;
669670

670-
// Find the equivalence class for this dependent member type.
671-
auto equivClass =
672-
builder.resolveEquivalenceClass(
673-
Type(component),
674-
ArchetypeResolutionKind::CompleteWellFormed);
671+
// Find the equivalence class for this dependent type.
672+
auto resolved = builder.maybeResolveEquivalenceClass(
673+
Type(component),
674+
ArchetypeResolutionKind::CompleteWellFormed,
675+
/*wantExactPotentialArchetype=*/false);
676+
if (!resolved) return None;
677+
678+
if (auto concrete = resolved.getAsConcreteType())
679+
return getCanonicalTypeInContext(concrete, builder);
680+
681+
auto equivClass = resolved.getEquivalenceClass(builder);
675682
if (!equivClass) return None;
676683

677684
if (equivClass->concreteType) {

0 commit comments

Comments
 (0)