Skip to content

Commit d7d77e9

Browse files
committed
[CS] Correctly set compound bit for UnresolvedMemberExprs
Now that IUOs are supported for compound function references, we can properly set the compound bit here. This is a source breaking change since this used to be legal: ```swift struct S { static func foo(x: Int) -> Self { .init() } } let _: S = .foo(x:)(x: 0) ``` However I somewhat doubt anyone is intentionally writing code like that.
1 parent 3c662c6 commit d7d77e9

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
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; }

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)