Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,23 +2170,22 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
SmallVector<SILValue, 8> params;

bindParametersForForwarding(fd->getParameters(), params);
if (thunk.kind != SILDeclRef::Kind::Allocator)
if (auto *selfDecl = fd->getImplicitSelfDecl())
bindParameterForForwarding(selfDecl, params);

// For allocating constructors, 'self' is a metatype, not the 'self' value
// formally present in the constructor body.
Type allocatorSelfType;
if (thunk.kind == SILDeclRef::Kind::Allocator) {
auto *selfDecl = fd->getImplicitSelfDecl();
allocatorSelfType = F.mapTypeIntoContext(
fd->getDeclContext()->getSelfInterfaceType());

auto selfMetatype =
CanMetatypeType::get(allocatorSelfType->getCanonicalType());
auto selfArg = F.begin()->createFunctionArgument(
getLoweredLoadableType(selfMetatype), selfDecl);
if (auto *selfDecl = fd->getImplicitSelfDecl()) {
// The self declaration sometimes differ in dynamic-self-ness from the
// lowered function type, so get the self parameter type from the function
// type rather than the declaration.
auto selfArgTy = F.getLoweredFunctionType()->getSelfParameter()
.getSILStorageType(getModule(), F.getLoweredFunctionType(), getTypeExpansionContext());
auto selfArg = F.begin()->createFunctionArgument(F.mapTypeIntoContext(selfArgTy), selfDecl);
params.push_back(selfArg);

// For allocating constructors, 'self' is a metatype, not the 'self' value
// formally present in the constructor body.
if (thunk.kind == SILDeclRef::Kind::Allocator) {
allocatorSelfType = F.mapTypeIntoContext(
fd->getDeclContext()->getSelfInterfaceType());
}
}

// Set up the throw destination if necessary.
Expand Down
7 changes: 7 additions & 0 deletions test/SILGen/Inputs/protocol-static-reqt-objc-class-impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import Foundation;

@interface C: NSObject

+(_Nonnull instancetype)foo;

@end
9 changes: 9 additions & 0 deletions test/SILGen/protocol-static-reqt-objc-class-impl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-emit-silgen(mock-sdk: %clang-importer-sdk) -import-objc-header %S/Inputs/protocol-static-reqt-objc-class-impl.h %s -verify
// REQUIRES: objc_interop

protocol P {
static func foo() -> Self
}

extension C: P {}