[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.
This commit is contained in:
Hamish Knight
2024-12-04 11:11:32 +00:00
parent 3c662c6276
commit d7d77e9e4b
3 changed files with 12 additions and 13 deletions

View File

@@ -1898,18 +1898,7 @@ public:
bool implicit)
: Expr(ExprKind::UnresolvedMember, implicit), DotLoc(dotLoc),
NameLoc(nameLoc), Name(name) {
// FIXME(FunctionRefInfo): Really, we should be passing `nameLoc` directly,
// allowing the FunctionRefInfo to be treated as compound. This would
// require us to enable IUOs for compound names, e.g:
// ```
// struct S {
// static func makeS(_: Int) -> S! { S() }
// }
//
// let s: S = .makeS(_:)(0)
// ```
setFunctionRefInfo(
FunctionRefInfo::unapplied(DeclNameLoc(nameLoc.getBaseNameLoc())));
setFunctionRefInfo(FunctionRefInfo::unapplied(nameLoc));
}
DeclNameRef getName() const { return Name; }

View File

@@ -837,3 +837,13 @@ do {
// expected-note@-2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
}
}
func testCompoundLeadingDot() {
struct S {
static func foo(x: Int) -> Self { .init() }
}
// Make sure we correctly strip the argument label.
let _: S = .foo(x:)(0)
let _: S = .foo(x:)(x: 0) // expected-error {{extraneous argument label 'x:' in call}}
}

View File

@@ -46,7 +46,7 @@ struct S0 {
}
// Determine context from type.
let s0_static: S0 = .f3(_:y:z:)(0, y: 0, z: 0)
let s0_static: S0 = .f3(_:y:z:)(0, 0, 0)
class C0 {
init(x: Int, y: Int, z: Int) { }