Skip to content

[5.0] Fix wrong missing-return error message for an initializer returning an implicitly unwrapped optional #14340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ SILGenFunction::emitPreconditionOptionalHasValue(SILLocation loc,
SGFContext());
}

B.createUnreachable(loc);
B.createUnreachable(ArtificialUnreachableLocation());
B.clearInsertionPoint();
B.emitBlock(contBB);

Expand Down
11 changes: 10 additions & 1 deletion test/SILOptimizer/return.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func whileLoop(flag: Bool) -> Int {
struct S {}
extension S:ExpressibleByStringLiteral {
init!(stringLiteral:String) {
} // expected-error {{missing return in a function expected to return 'S!'}}
} // no error
}

func whileTrueLoop() -> Int {
Expand Down Expand Up @@ -150,3 +150,12 @@ func testCleanupCodeEmptyTuple(fn: @autoclosure () -> Bool = false,
exit()
}
} // no warning

protocol InitProtocol {
init(_ x: Int)
}

struct StructWithIUOinit : InitProtocol {
init!(_ x: Int) { } // no missing-return error
}