Skip to content

Commit 00f6df9

Browse files
authored
Merge pull request swiftlang#77944 from hamishknight/compound-ume
[CS] Correctly set compound bit for UnresolvedMemberExprs
2 parents 065eb83 + d7d77e9 commit 00f6df9

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,18 +1898,7 @@ class UnresolvedMemberExpr final
18981898
bool implicit)
18991899
: Expr(ExprKind::UnresolvedMember, implicit), DotLoc(dotLoc),
19001900
NameLoc(nameLoc), Name(name) {
1901-
// FIXME(FunctionRefInfo): Really, we should be passing `nameLoc` directly,
1902-
// allowing the FunctionRefInfo to be treated as compound. This would
1903-
// require us to enable IUOs for compound names, e.g:
1904-
// ```
1905-
// struct S {
1906-
// static func makeS(_: Int) -> S! { S() }
1907-
// }
1908-
//
1909-
// let s: S = .makeS(_:)(0)
1910-
// ```
1911-
setFunctionRefInfo(
1912-
FunctionRefInfo::unapplied(DeclNameLoc(nameLoc.getBaseNameLoc())));
1901+
setFunctionRefInfo(FunctionRefInfo::unapplied(nameLoc));
19131902
}
19141903

19151904
DeclNameRef getName() const { return Name; }

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+
}

test/Constraints/members.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,13 @@ do {
837837
// expected-note@-2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
838838
}
839839
}
840+
841+
func testCompoundLeadingDot() {
842+
struct S {
843+
static func foo(x: Int) -> Self { .init() }
844+
}
845+
846+
// Make sure we correctly strip the argument label.
847+
let _: S = .foo(x:)(0)
848+
let _: S = .foo(x:)(x: 0) // expected-error {{extraneous argument label 'x:' in call}}
849+
}

test/expr/primary/unqualified_name.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct S0 {
4646
}
4747

4848
// Determine context from type.
49-
let s0_static: S0 = .f3(_:y:z:)(0, y: 0, z: 0)
49+
let s0_static: S0 = .f3(_:y:z:)(0, 0, 0)
5050

5151
class C0 {
5252
init(x: Int, y: Int, z: Int) { }

0 commit comments

Comments
 (0)