Skip to content

Commit 3c662c6

Browse files
committed
[CS] Support IUOs for compound function references
This was previously an artificial limitation of the FunctionRefKind representation, there's no reason we shouldn't support IUOs for functions referenced using a compound name.
1 parent 66321f7 commit 3c662c6

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,11 +1955,6 @@ OverloadChoice::getIUOReferenceKind(ConstraintSystem &cs,
19551955
auto refKind = getFunctionRefInfo();
19561956
assert(!forSecondApplication || refKind.isDoubleApply());
19571957

1958-
// Compound references currently never produce IUOs.
1959-
// FIXME(FunctionRefInfo): They should.
1960-
if (refKind.isCompoundName())
1961-
return std::nullopt;
1962-
19631958
switch (refKind.getApplyLevel()) {
19641959
case FunctionRefInfo::ApplyLevel::Unapplied:
19651960
// Such references never produce IUOs.

test/Constraints/iuo.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,26 @@ let _: Int? = returnsIUOFn()()
260260
let _: Int = returnsIUOFn()() // expected-error {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
261261
// expected-note@-1 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
262262
// expected-note@-2 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
263+
264+
// Make sure it works for compound function references.
265+
func testCompoundRefs() {
266+
func hasArgLabel(x: Int) -> Int! { x }
267+
struct S {
268+
func hasArgLabel(x: Int) -> Int! { x }
269+
}
270+
let _ = hasArgLabel(x:)(0)
271+
let _: Int? = hasArgLabel(x:)(0)
272+
let _: Int = hasArgLabel(x:)(0)
273+
274+
let _ = S.hasArgLabel(x:)(S())(0)
275+
let _: Int? = S.hasArgLabel(x:)(S())(0)
276+
let _: Int = S.hasArgLabel(x:)(S())(0)
277+
278+
let _ = S().hasArgLabel(x:)(0)
279+
let _: Int? = S().hasArgLabel(x:)(0)
280+
let _: Int = S().hasArgLabel(x:)(0)
281+
282+
// We still don't allow IUOs for the function itself.
283+
let _: (Int) -> Int = hasArgLabel(x:) // expected-error {{cannot convert value of type '(Int) -> Int?' to specified type '(Int) -> Int}}
284+
let _: (Int) -> Int? = hasArgLabel(x:)
285+
}

0 commit comments

Comments
 (0)