Skip to content

Ban IUOs in more places. #12746

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
Nov 4, 2017
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
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,9 @@ Type TypeResolver::resolveTupleType(TupleTypeRepr *repr,
// ImmediateFunctionInput marker and install a FunctionInput one instead.
auto elementOptions = options;
if (repr->isParenType()) {
// We also want to disallow IUO within even a paren.
elementOptions -= TR_AllowIUO;

// If we have a single ParenType, don't clear the context bits; we
// still want to parse the type contained therein as if it were in
// parameter position, meaning function types are not @escaping by
Expand Down
16 changes: 16 additions & 0 deletions test/Sema/diag_erroneous_iuo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,19 @@ let _: Generic<Int!, // expected-error {{implicitly unwrapped optionals are only

func vararg(_ first: Int, more: Int!...) { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
}

func iuoInTuple() -> (Int!) { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
return 1
}

func iuoInTuple2() -> (Float, Int!) { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
return 1
}

func takesFunc(_ fn: (Int!) -> Int) -> Int { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
return fn(0)
}

func returnsFunc() -> (Int!) -> Int { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
return { $0 }
}