Skip to content

Commit b1092f8

Browse files
authored
Merge pull request #14272 from eeckstein/fix-error-msg
Fix wrong missing-return error message for an initializer returning an implicitly unwrapped optional
2 parents a436044 + 0661380 commit b1092f8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/SILGen/SILGenConvert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ SILGenFunction::emitPreconditionOptionalHasValue(SILLocation loc,
223223
SGFContext());
224224
}
225225

226-
B.createUnreachable(loc);
226+
B.createUnreachable(ArtificialUnreachableLocation());
227227
B.clearInsertionPoint();
228228
B.emitBlock(contBB);
229229

test/SILOptimizer/return.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func whileLoop(flag: Bool) -> Int {
9797
struct S {}
9898
extension S:ExpressibleByStringLiteral {
9999
init!(stringLiteral:String) {
100-
} // expected-error {{missing return in a function expected to return 'S!'}}
100+
} // no error
101101
}
102102

103103
func whileTrueLoop() -> Int {
@@ -150,3 +150,12 @@ func testCleanupCodeEmptyTuple(fn: @autoclosure () -> Bool = false,
150150
exit()
151151
}
152152
} // no warning
153+
154+
protocol InitProtocol {
155+
init(_ x: Int)
156+
}
157+
158+
struct StructWithIUOinit : InitProtocol {
159+
init!(_ x: Int) { } // no missing-return error
160+
}
161+

0 commit comments

Comments
 (0)