Skip to content

Commit 666c000

Browse files
committed
[CSDiagnostics] Use getExistentialLayout() to check if we need a class
1 parent ab11842 commit 666c000

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "TypoCorrection.h"
2121
#include "swift/AST/ASTContext.h"
2222
#include "swift/AST/Decl.h"
23+
#include "swift/AST/ExistentialLayout.h"
2324
#include "swift/AST/Expr.h"
2425
#include "swift/AST/GenericSignature.h"
2526
#include "swift/AST/Initializer.h"
@@ -2452,12 +2453,7 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24522453
// is a struct), then bail out instead of offering a broken fix-it later on.
24532454
auto requiresClass = false;
24542455
if (unwrappedToType->isExistentialType()) {
2455-
if (auto protocolTy = unwrappedToType->getAs<ProtocolType>()) {
2456-
requiresClass = protocolTy->requiresClass();
2457-
} else if (auto compositionTy =
2458-
unwrappedToType->getAs<ProtocolCompositionType>()) {
2459-
requiresClass = compositionTy->requiresClass();
2460-
}
2456+
requiresClass = unwrappedToType->getExistentialLayout().requiresClass();
24612457
}
24622458
if (requiresClass && !FromType->is<ClassType>()) {
24632459
return false;
@@ -2486,7 +2482,6 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
24862482
missingProtoTypeStrings.push_back(memberTy->getString());
24872483
}
24882484
}
2489-
24902485
// If we don't conform to all of the protocols in the composition, then
24912486
// store the composition type only. This is because we need to append
24922487
// 'Foo & Bar' instead of 'Foo, Bar' in order to match the written type.

0 commit comments

Comments
 (0)