Skip to content

Commit b5ab1c8

Browse files
authored
Fix bug: wrong var used (#62683)
* Fix bug: wrong var used * Augment tests for cases returning from initializers without initializing all stored properties
1 parent f97bf69 commit b5ab1c8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void diagnoseMissingReturn(const UnreachableInst *UI,
5050
BS = FD->getBody(/*canSynthesize=*/false);
5151
} else if (auto *CD = FLoc.getAsASTNode<ConstructorDecl>()) {
5252
ResTy = CD->getResultInterfaceType();
53-
BS = FD->getBody();
53+
BS = CD->getBody();
5454
} else if (auto *CE = FLoc.getAsASTNode<ClosureExpr>()) {
5555
ResTy = CE->getResultType();
5656
BS = CE->getBody();

test/SILOptimizer/return.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ func f_56150() {
220220
// https://github.com/apple/swift/issues/56857
221221

222222
struct S_56857 {
223-
let b = true
223+
init(_ i: Int) {
224+
if i > 0 {
225+
b = false
226+
}
227+
} // expected-error {{return from initializer without initializing all stored properties}}
228+
229+
let b: Bool // expected-note {{'self.b' not initialized}}
230+
224231
var x: Int {
225232
if b {
226233
return 0
@@ -238,8 +245,14 @@ struct S_56857 {
238245
}
239246

240247
class C_56857 {
248+
init(_ i: Int) {
249+
if i > 0 {
250+
b = false
251+
}
252+
} // expected-error {{return from initializer without initializing all stored properties}}
253+
241254
static let a = false
242-
let b = true
255+
let b: Bool // expected-note {{'self.b' not initialized}}
243256

244257
func method() -> Int {
245258
if b {

0 commit comments

Comments
 (0)