Skip to content

Commit ab934d0

Browse files
committed
DefiniteInitialization: fixed crash for wrong super call with inout instance variable
Fixes rdar://problem/22960985
1 parent c2afdc4 commit ab934d0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ void LifetimeChecker::handleInOutUse(const DIMemoryUse &Use) {
10941094
if (auto *DSCE = dyn_cast<SelfApplyExpr>(CE->getFn()))
10951095
// Normal method calls are curried, so they are:
10961096
// (call_expr (dot_syntax_call_expr (decl_ref_expr METHOD)))
1097-
FD = dyn_cast<FuncDecl>(DSCE->getCalledValue());
1097+
FD = dyn_cast_or_null<FuncDecl>(DSCE->getCalledValue());
10981098
else
10991099
// Operators and normal function calls are just (CallExpr DRE)
11001100
FD = dyn_cast_or_null<FuncDecl>(CE->getCalledValue());
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-sil -verify %s -o /dev/null
2+
3+
class B {
4+
init(x: inout Int) {}
5+
}
6+
7+
class A : B {
8+
let x: Int
9+
10+
init() {
11+
self.x = 12
12+
super.init(x: &x) // expected-error {{immutable value 'self.x' must not be passed inout}}
13+
} // expected-error {{super.init isn't called on all paths before returning from initializer}}
14+
}
15+

0 commit comments

Comments
 (0)