Skip to content

Commit 390c635

Browse files
committed
Sema: Prevented an invalid coercion when handling member access in accesses through metatypes
1 parent 8f0d997 commit 390c635

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/Sema/CSApply.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,10 @@ namespace {
820820
// Figure out the actual base type, and whether we have an instance of
821821
// that type or its metatype.
822822
bool baseIsInstance = true;
823+
bool isExistentialMetatype = false;
823824
if (auto baseMeta = baseTy->getAs<AnyMetatypeType>()) {
824825
baseIsInstance = false;
826+
isExistentialMetatype = baseMeta->is<ExistentialMetatypeType>();
825827
baseTy = baseMeta->getInstanceType();
826828
}
827829

@@ -909,11 +911,15 @@ namespace {
909911
base, selfParamTy, member, semantics,
910912
locator.withPathElement(ConstraintLocator::MemberRefBase));
911913
} else {
912-
// Convert the base to an rvalue of the appropriate metatype.
913-
base = coerceToType(base,
914-
MetatypeType::get(isDynamic ? selfTy : containerTy),
915-
locator.withPathElement(
916-
ConstraintLocator::MemberRefBase));
914+
if (!isExistentialMetatype) {
915+
// Convert the base to an rvalue of the appropriate metatype.
916+
base = coerceToType(base,
917+
MetatypeType::get(
918+
isDynamic ? selfTy : containerTy),
919+
locator.withPathElement(
920+
ConstraintLocator::MemberRefBase));
921+
}
922+
917923
if (!base)
918924
return nullptr;
919925

@@ -6452,12 +6458,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
64526458
}
64536459
}
64546460

6455-
// Allows for same-type coercion with existential metatypes.
6456-
if (auto toMeta = toType->getAs<AnyMetatypeType>()) {
6457-
if (fromMeta->getInstanceType()->isEqual(toMeta->getInstanceType()))
6458-
return expr;
6459-
}
6460-
64616461
break;
64626462
}
64636463

0 commit comments

Comments
 (0)