@@ -4372,12 +4372,33 @@ namespace {
4372
4372
clangModule))
4373
4373
return native;
4374
4374
4375
- Impl.addImportDiagnostic (
4376
- decl, Diagnostic (diag::forward_declared_protocol_label, decl),
4377
- decl->getSourceRange ().getBegin ());
4375
+ if (Impl.ImportForwardDeclarations ) {
4376
+ auto result = Impl.createDeclWithClangNode <ProtocolDecl>(
4377
+ decl, AccessLevel::Public,
4378
+ Impl.getClangModuleForDecl (decl->getCanonicalDecl (),
4379
+ /* allowForwardDeclaration=*/ true ),
4380
+ SourceLoc (), SourceLoc (), name,
4381
+ ArrayRef<PrimaryAssociatedTypeName>(), None,
4382
+ /* TrailingWhere=*/ nullptr );
4383
+
4384
+ Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = result;
4385
+ result->setSuperclass (Impl.getNSObjectProtocolType ());
4386
+ result->setAddedImplicitInitializers (); // suppress all initializers
4387
+ addObjCAttribute (result,
4388
+ Impl.importIdentifier (decl->getIdentifier ()));
4389
+ SmallVector<InheritedEntry, 4 > inheritedTypes = {
4390
+ TypeLoc::withoutLoc (Impl.getNSObjectProtocolType ())};
4391
+ result->setInherited (Impl.SwiftContext .AllocateCopy (inheritedTypes));
4392
+ result->setImplicit ();
4393
+ return result;
4394
+ } else {
4395
+ Impl.addImportDiagnostic (
4396
+ decl, Diagnostic (diag::forward_declared_protocol_label, decl),
4397
+ decl->getSourceRange ().getBegin ());
4378
4398
4379
- forwardDeclaration = true ;
4380
- return nullptr ;
4399
+ forwardDeclaration = true ;
4400
+ return nullptr ;
4401
+ }
4381
4402
}
4382
4403
4383
4404
decl = decl->getDefinition ();
@@ -4443,7 +4464,7 @@ namespace {
4443
4464
nullptr , dc,
4444
4465
/* isActor*/ false );
4445
4466
Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = result;
4446
- result->setSuperclass (Type ());
4467
+ result->setSuperclass (Impl. getNSObjectType ());
4447
4468
result->setAddedImplicitInitializers (); // suppress all initializers
4448
4469
result->setHasMissingVTableEntries (false );
4449
4470
addObjCAttribute (result, Impl.importIdentifier (decl->getIdentifier ()));
@@ -4497,15 +4518,23 @@ namespace {
4497
4518
}
4498
4519
4499
4520
if (Impl.ImportForwardDeclarations ) {
4500
- // Fake it by making an unavailable opaque @objc root class.
4501
- auto result = createFakeRootClass (name);
4521
+ auto result = Impl.createDeclWithClangNode <ClassDecl>(
4522
+ decl, AccessLevel::Public, SourceLoc (), name, SourceLoc (), None,
4523
+ nullptr ,
4524
+ Impl.getClangModuleForDecl (decl->getCanonicalDecl (),
4525
+ /* allowForwardDeclaration=*/ true ),
4526
+ /* isActor*/ false );
4527
+ Type superclassType = Impl.getNSObjectType ();
4528
+ Impl.ImportedDecls [{decl->getCanonicalDecl (), getVersion ()}] = result;
4529
+ SmallVector<InheritedEntry, 4 > inheritedTypes{
4530
+ TypeLoc::withoutLoc (superclassType)};
4531
+ result->setInherited (Impl.SwiftContext .AllocateCopy (inheritedTypes));
4532
+ result->setSuperclass (superclassType);
4533
+ result->setAddedImplicitInitializers (); // suppress all initializers
4534
+ result->setHasMissingVTableEntries (false );
4535
+ addObjCAttribute (result,
4536
+ Impl.importIdentifier (decl->getIdentifier ()));
4502
4537
result->setImplicit ();
4503
- auto attr = AvailableAttr::createPlatformAgnostic (Impl.SwiftContext ,
4504
- " This Objective-C class has only been forward-declared; "
4505
- " import its owning module to use it" );
4506
- result->getAttrs ().add (attr);
4507
- result->getAttrs ().add (
4508
- new (Impl.SwiftContext ) ForbidSerializingReferenceAttr (true ));
4509
4538
return result;
4510
4539
} else {
4511
4540
Impl.addImportDiagnostic (
0 commit comments