Skip to content

Commit d3a3709

Browse files
committed
Make sure we propagate 'async' down to inherited designed initializes.
Fixes a crash reported via rdar://80353441.
1 parent 246896f commit d3a3709

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ synthesizeDesignatedInitOverride(AbstractFunctionDecl *fn, void *context) {
662662

663663
Expr *expr = superclassCallExpr;
664664

665+
if (superclassCtor->hasAsync()) {
666+
expr = new (ctx) AwaitExpr(SourceLoc(), expr, type, /*implicit=*/true);
667+
}
665668
if (superclassCtor->hasThrows()) {
666669
expr = new (ctx) TryExpr(SourceLoc(), expr, type, /*implicit=*/true);
667670
}
@@ -777,7 +780,8 @@ createDesignatedInitOverride(ClassDecl *classDecl,
777780
classDecl->getBraces().Start,
778781
superclassCtor->isFailable(),
779782
/*FailabilityLoc=*/SourceLoc(),
780-
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
783+
/*Async=*/superclassCtor->hasAsync(),
784+
/*AsyncLoc=*/SourceLoc(),
781785
/*Throws=*/superclassCtor->hasThrows(),
782786
/*ThrowsLoc=*/SourceLoc(),
783787
bodyParams, overrideInfo.GenericParams,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -emit-sil %s
2+
3+
// Properly make inherited initializers 'async' when needed.
4+
@available(SwiftStdlib 5.5, *)
5+
class Base {
6+
required init() async { }
7+
}
8+
9+
@available(SwiftStdlib 5.5, *)
10+
class Derived: Base { }
11+
12+
13+
@available(SwiftStdlib 5.5, *)
14+
class Base2 {
15+
required init() async throws { }
16+
}
17+
18+
@available(SwiftStdlib 5.5, *)
19+
class Derived2: Base2 { }
20+

0 commit comments

Comments
 (0)