@@ -4382,6 +4382,11 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
4382
4382
DeclRefExpr *getInteropStaticCastDeclRefExpr (ASTContext &ctx,
4383
4383
const clang::Module *owningModule,
4384
4384
Type base, Type derived) {
4385
+ if (base->isForeignReferenceType () && derived->isForeignReferenceType ()) {
4386
+ base = base->wrapInPointer (PTK_UnsafePointer);
4387
+ derived = derived->wrapInPointer (PTK_UnsafePointer);
4388
+ }
4389
+
4385
4390
// Lookup our static cast helper function.
4386
4391
// TODO: change this to stdlib or something.
4387
4392
auto wrapperModule =
@@ -4420,8 +4425,8 @@ DeclRefExpr *getInteropStaticCastDeclRefExpr(ASTContext &ctx,
4420
4425
// %3 = %2!
4421
4426
// return %3.pointee
4422
4427
MemberRefExpr *getInOutSelfInteropStaticCast (FuncDecl *funcDecl,
4423
- StructDecl *baseStruct,
4424
- StructDecl *derivedStruct) {
4428
+ NominalTypeDecl *baseStruct,
4429
+ NominalTypeDecl *derivedStruct) {
4425
4430
auto &ctx = funcDecl->getASTContext ();
4426
4431
4427
4432
auto inoutSelf = [&ctx](FuncDecl *funcDecl) {
@@ -4485,18 +4490,13 @@ MemberRefExpr *getInOutSelfInteropStaticCast(FuncDecl *funcDecl,
4485
4490
->getResult ());
4486
4491
casted->setThrows (false );
4487
4492
4488
- // Now force unwrap the casted pointer.
4489
- auto unwrapped = new (ctx) ForceValueExpr (casted, SourceLoc ());
4490
- unwrapped->setType (baseStruct->getSelfInterfaceType ()->wrapInPointer (
4491
- PTK_UnsafeMutablePointer));
4492
-
4493
4493
SubstitutionMap pointeeSubst = SubstitutionMap::get (
4494
4494
ctx.getUnsafeMutablePointerDecl ()->getGenericSignature (),
4495
4495
{baseStruct->getSelfInterfaceType ()}, {});
4496
4496
VarDecl *pointeePropertyDecl =
4497
4497
ctx.getPointerPointeePropertyDecl (PTK_UnsafeMutablePointer);
4498
4498
auto pointeePropertyRefExpr = new (ctx) MemberRefExpr (
4499
- unwrapped , SourceLoc (),
4499
+ casted , SourceLoc (),
4500
4500
ConcreteDeclRef (pointeePropertyDecl, pointeeSubst), DeclNameLoc (),
4501
4501
/* implicit=*/ true );
4502
4502
pointeePropertyRefExpr->setType (
@@ -4521,9 +4521,9 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
4521
4521
4522
4522
auto funcDecl = cast<FuncDecl>(afd);
4523
4523
auto derivedStruct =
4524
- cast<StructDecl >(funcDecl->getDeclContext ()->getAsDecl ());
4524
+ cast<NominalTypeDecl >(funcDecl->getDeclContext ()->getAsDecl ());
4525
4525
auto baseMember = static_cast <FuncDecl *>(context);
4526
- auto baseStruct = cast<StructDecl >(baseMember->getDeclContext ()->getAsDecl ());
4526
+ auto baseStruct = cast<NominalTypeDecl >(baseMember->getDeclContext ()->getAsDecl ());
4527
4527
auto baseType = baseStruct->getDeclaredType ();
4528
4528
4529
4529
SmallVector<Expr *, 8 > forwardingParams;
@@ -4591,10 +4591,10 @@ synthesizeBaseClassFieldGetterBody(AbstractFunctionDecl *afd, void *context) {
4591
4591
4592
4592
AccessorDecl *getterDecl = cast<AccessorDecl>(afd);
4593
4593
AbstractStorageDecl *baseClassVar = static_cast <AbstractStorageDecl *>(context);
4594
- StructDecl *baseStruct =
4595
- cast<StructDecl >(baseClassVar->getDeclContext ()->getAsDecl ());
4596
- StructDecl *derivedStruct =
4597
- cast<StructDecl >(getterDecl->getDeclContext ()->getAsDecl ());
4594
+ NominalTypeDecl *baseStruct =
4595
+ cast<NominalTypeDecl >(baseClassVar->getDeclContext ()->getAsDecl ());
4596
+ NominalTypeDecl *derivedStruct =
4597
+ cast<NominalTypeDecl >(getterDecl->getDeclContext ()->getAsDecl ());
4598
4598
4599
4599
auto selfDecl = getterDecl->getImplicitSelfDecl ();
4600
4600
auto selfExpr = new (ctx) DeclRefExpr (selfDecl, DeclNameLoc (),
@@ -4654,10 +4654,10 @@ synthesizeBaseClassFieldSetterBody(AbstractFunctionDecl *afd, void *context) {
4654
4654
AbstractStorageDecl *baseClassVar = static_cast <AbstractStorageDecl *>(context);
4655
4655
ASTContext &ctx = setterDecl->getASTContext ();
4656
4656
4657
- StructDecl *baseStruct =
4658
- cast<StructDecl >(baseClassVar->getDeclContext ()->getAsDecl ());
4659
- StructDecl *derivedStruct =
4660
- cast<StructDecl >(setterDecl->getDeclContext ()->getAsDecl ());
4657
+ NominalTypeDecl *baseStruct =
4658
+ cast<NominalTypeDecl >(baseClassVar->getDeclContext ()->getAsDecl ());
4659
+ NominalTypeDecl *derivedStruct =
4660
+ cast<NominalTypeDecl >(setterDecl->getDeclContext ()->getAsDecl ());
4661
4661
4662
4662
auto *pointeePropertyRefExpr =
4663
4663
getInOutSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
@@ -4894,7 +4894,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
4894
4894
if (cast<ValueDecl>(import )->getName () == name)
4895
4895
continue ;
4896
4896
4897
- auto baseResults = cast<StructDecl >(import )->lookupDirect (name);
4897
+ auto baseResults = cast<NominalTypeDecl >(import )->lookupDirect (name);
4898
4898
for (auto foundInBase : baseResults) {
4899
4899
if (auto newDecl = cloneBaseMemberDecl (foundInBase, recordDecl)) {
4900
4900
result.push_back (newDecl);
0 commit comments