@@ -4382,6 +4382,11 @@ TinyPtrVector<ValueDecl *> CXXNamespaceMemberLookup::evaluate(
43824382DeclRefExpr *getInteropStaticCastDeclRefExpr (ASTContext &ctx,
43834383 const clang::Module *owningModule,
43844384 Type base, Type derived) {
4385+ if (base->isForeignReferenceType () && derived->isForeignReferenceType ()) {
4386+ base = base->wrapInPointer (PTK_UnsafePointer);
4387+ derived = derived->wrapInPointer (PTK_UnsafePointer);
4388+ }
4389+
43854390 // Lookup our static cast helper function.
43864391 // TODO: change this to stdlib or something.
43874392 auto wrapperModule =
@@ -4420,8 +4425,8 @@ DeclRefExpr *getInteropStaticCastDeclRefExpr(ASTContext &ctx,
44204425// %3 = %2!
44214426// return %3.pointee
44224427MemberRefExpr *getInOutSelfInteropStaticCast (FuncDecl *funcDecl,
4423- StructDecl *baseStruct,
4424- StructDecl *derivedStruct) {
4428+ NominalTypeDecl *baseStruct,
4429+ NominalTypeDecl *derivedStruct) {
44254430 auto &ctx = funcDecl->getASTContext ();
44264431
44274432 auto inoutSelf = [&ctx](FuncDecl *funcDecl) {
@@ -4485,18 +4490,13 @@ MemberRefExpr *getInOutSelfInteropStaticCast(FuncDecl *funcDecl,
44854490 ->getResult ());
44864491 casted->setThrows (false );
44874492
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-
44934493 SubstitutionMap pointeeSubst = SubstitutionMap::get (
44944494 ctx.getUnsafeMutablePointerDecl ()->getGenericSignature (),
44954495 {baseStruct->getSelfInterfaceType ()}, {});
44964496 VarDecl *pointeePropertyDecl =
44974497 ctx.getPointerPointeePropertyDecl (PTK_UnsafeMutablePointer);
44984498 auto pointeePropertyRefExpr = new (ctx) MemberRefExpr (
4499- unwrapped , SourceLoc (),
4499+ casted , SourceLoc (),
45004500 ConcreteDeclRef (pointeePropertyDecl, pointeeSubst), DeclNameLoc (),
45014501 /* implicit=*/ true );
45024502 pointeePropertyRefExpr->setType (
@@ -4521,9 +4521,9 @@ synthesizeBaseClassMethodBody(AbstractFunctionDecl *afd, void *context) {
45214521
45224522 auto funcDecl = cast<FuncDecl>(afd);
45234523 auto derivedStruct =
4524- cast<StructDecl >(funcDecl->getDeclContext ()->getAsDecl ());
4524+ cast<NominalTypeDecl >(funcDecl->getDeclContext ()->getAsDecl ());
45254525 auto baseMember = static_cast <FuncDecl *>(context);
4526- auto baseStruct = cast<StructDecl >(baseMember->getDeclContext ()->getAsDecl ());
4526+ auto baseStruct = cast<NominalTypeDecl >(baseMember->getDeclContext ()->getAsDecl ());
45274527 auto baseType = baseStruct->getDeclaredType ();
45284528
45294529 SmallVector<Expr *, 8 > forwardingParams;
@@ -4591,10 +4591,10 @@ synthesizeBaseClassFieldGetterBody(AbstractFunctionDecl *afd, void *context) {
45914591
45924592 AccessorDecl *getterDecl = cast<AccessorDecl>(afd);
45934593 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 ());
45984598
45994599 auto selfDecl = getterDecl->getImplicitSelfDecl ();
46004600 auto selfExpr = new (ctx) DeclRefExpr (selfDecl, DeclNameLoc (),
@@ -4654,10 +4654,10 @@ synthesizeBaseClassFieldSetterBody(AbstractFunctionDecl *afd, void *context) {
46544654 AbstractStorageDecl *baseClassVar = static_cast <AbstractStorageDecl *>(context);
46554655 ASTContext &ctx = setterDecl->getASTContext ();
46564656
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 ());
46614661
46624662 auto *pointeePropertyRefExpr =
46634663 getInOutSelfInteropStaticCast (setterDecl, baseStruct, derivedStruct);
@@ -4894,7 +4894,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
48944894 if (cast<ValueDecl>(import )->getName () == name)
48954895 continue ;
48964896
4897- auto baseResults = cast<StructDecl >(import )->lookupDirect (name);
4897+ auto baseResults = cast<NominalTypeDecl >(import )->lookupDirect (name);
48984898 for (auto foundInBase : baseResults) {
48994899 if (auto newDecl = cloneBaseMemberDecl (foundInBase, recordDecl)) {
49004900 result.push_back (newDecl);
0 commit comments