Skip to content

Commit 6062204

Browse files
authored
Merge pull request #12746 from rudkx/ban-iuo-in-tuple
Ban IUOs in more places.
2 parents 2e5b982 + b38d967 commit 6062204

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,6 +2845,9 @@ Type TypeResolver::resolveTupleType(TupleTypeRepr *repr,
28452845
// ImmediateFunctionInput marker and install a FunctionInput one instead.
28462846
auto elementOptions = options;
28472847
if (repr->isParenType()) {
2848+
// We also want to disallow IUO within even a paren.
2849+
elementOptions -= TR_AllowIUO;
2850+
28482851
// If we have a single ParenType, don't clear the context bits; we
28492852
// still want to parse the type contained therein as if it were in
28502853
// parameter position, meaning function types are not @escaping by

test/Sema/diag_erroneous_iuo.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,19 @@ let _: Generic<Int!, // expected-error {{implicitly unwrapped optionals are only
137137

138138
func vararg(_ first: Int, more: Int!...) { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
139139
}
140+
141+
func iuoInTuple() -> (Int!) { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
142+
return 1
143+
}
144+
145+
func iuoInTuple2() -> (Float, Int!) { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
146+
return 1
147+
}
148+
149+
func takesFunc(_ fn: (Int!) -> Int) -> Int { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
150+
return fn(0)
151+
}
152+
153+
func returnsFunc() -> (Int!) -> Int { // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
154+
return { $0 }
155+
}

0 commit comments

Comments
 (0)