Skip to content

Commit 6c8dd39

Browse files
committed
[AST] Dodge an annoying libc++ std::function quirk requiring complete result types
1 parent f146e16 commit 6c8dd39

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

include/swift/AST/Type.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,11 @@ enum class SubstFlags {
166166

167167
/// Options for performing substitutions into a type.
168168
struct SubstOptions : public OptionSet<SubstFlags> {
169-
typedef std::function<Type(const NormalProtocolConformance *,
170-
AssociatedTypeDecl *)>
169+
// Note: The unfortunate use of TypeBase * here, rather than Type,
170+
// is due to a libc++ quirk that requires the result type to be
171+
// complete.
172+
typedef std::function<TypeBase *(const NormalProtocolConformance *,
173+
AssociatedTypeDecl *)>
171174
GetTentativeTypeWitness;
172175

173176
/// Function that retrieves a tentative type witness for a protocol

lib/AST/ProtocolConformance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ NormalProtocolConformance::getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
490490
if (getState() == ProtocolConformanceState::CheckingTypeWitnesses) {
491491
// If there is a tentative-type-witness function, use it.
492492
if (options.getTentativeTypeWitness) {
493-
if (Type witnessType = options.getTentativeTypeWitness(this, assocType))
493+
if (Type witnessType =
494+
Type(options.getTentativeTypeWitness(this, assocType)))
494495
return { witnessType, nullptr };
495496
}
496497

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,10 +4204,10 @@ void ConformanceChecker::resolveTypeWitnesses() {
42044204
SubstOptions options(None);
42054205
options.getTentativeTypeWitness =
42064206
[&](const NormalProtocolConformance *conformance,
4207-
AssociatedTypeDecl *assocType) -> Type {
4208-
if (conformance != Conformance) return Type(0);
4207+
AssociatedTypeDecl *assocType) -> TypeBase * {
4208+
if (conformance != Conformance) return nullptr;
42094209

4210-
return typeWitnesses.begin(assocType)->first;
4210+
return typeWitnesses.begin(assocType)->first.getPointer();
42114211
};
42124212

42134213
auto substitutions =

0 commit comments

Comments
 (0)