Skip to content

Commit 8adcc2a

Browse files
authored
Merge pull request #41594 from slavapestov/rqm-foreign-function-type-cycle
Sema: Fix cycle in structural type resolution via TypeChecker::diagnoseInvalidFunctionType()
2 parents c880534 + b5fa1ac commit 8adcc2a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Sema/TypeChecker.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,12 @@ bool TypeChecker::diagnoseInvalidFunctionType(FunctionType *fnTy, SourceLoc loc,
543543
Optional<FunctionTypeRepr *>repr,
544544
DeclContext *dc,
545545
Optional<TypeResolutionStage> stage) {
546+
// Some of the below checks trigger cycles if we don't have a generic
547+
// signature yet; we'll run the checks again in
548+
// TypeResolutionStage::Interface.
549+
if (stage == TypeResolutionStage::Structural)
550+
return false;
551+
546552
// If the type has a placeholder, don't try to diagnose anything now since
547553
// we'll produce a better diagnostic when (if) the expression successfully
548554
// typechecks.
@@ -582,8 +588,7 @@ bool TypeChecker::diagnoseInvalidFunctionType(FunctionType *fnTy, SourceLoc loc,
582588

583589
// `@differentiable` function types must return a differentiable type and have
584590
// differentiable (or `@noDerivative`) parameters.
585-
if (extInfo.isDifferentiable() &&
586-
stage != TypeResolutionStage::Structural) {
591+
if (extInfo.isDifferentiable()) {
587592
auto result = fnTy->getResult();
588593
auto params = fnTy->getParams();
589594
auto diffKind = extInfo.getDifferentiabilityKind();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend -typecheck %s -requirement-machine-protocol-signatures=on
2+
3+
protocol P {
4+
typealias MyFunction =
5+
@convention(c) (UnsafeMutableRawPointer?,
6+
UnsafeMutableRawPointer?,
7+
UnsafeMutableRawPointer?) -> CInt
8+
}
9+

0 commit comments

Comments
 (0)