Skip to content

Commit 69ef789

Browse files
committed
[Constraint solver] Match argument labels for unresolved member expressions.
1 parent e561329 commit 69ef789

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,6 +3607,14 @@ namespace {
36073607
return { true, expr };
36083608
}
36093609

3610+
if (auto unresolvedMember = dyn_cast<UnresolvedMemberExpr>(expr)) {
3611+
associateArgumentLabels(unresolvedMember,
3612+
{ unresolvedMember->getArgumentLabels(),
3613+
unresolvedMember->hasTrailingClosure() },
3614+
/*labelsArePermanent=*/true);
3615+
return { true, expr };
3616+
}
3617+
36103618
// FIXME: other expressions have argument labels, but this is an
36113619
// optimization, so stage it in later.
36123620
return { true, expr };

test/Constraints/generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ let arr = [BottleLayout]()
630630
let layout = BottleLayout(count:1)
631631
let ix = arr.firstIndex(of:layout) // expected-error {{argument type 'BottleLayout' does not conform to expected type 'Equatable'}}
632632

633-
let _: () -> UInt8 = { .init("a" as Unicode.Scalar) } // expected-error {{missing argument label 'ascii:' in call}}
633+
let _: () -> UInt8 = { .init("a" as Unicode.Scalar) } // expected-error {{initializer 'init(_:)' requires that 'Unicode.Scalar' conform to 'BinaryInteger'}}
634634

635635
// https://bugs.swift.org/browse/SR-9068
636636
func compare<C: Collection, Key: Hashable, Value: Equatable>(c: C)

test/Constraints/overload_filtering.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ struct X {
1919
subscript(_: Int) -> Int { return 0 }
2020
subscript(_: Int, _: Int) -> Double { return 0 }
2121
subscript(_: Int, _: Int, _: Int) -> String { return "" }
22+
23+
init(_: Int) { }
24+
init(_: Int, _: Int) { }
25+
init(_: Int, _: Int, _: Int) { }
2226
}
2327

2428
func testSubscript(x: X, i: Int) {
@@ -28,3 +32,10 @@ func testSubscript(x: X, i: Int) {
2832
// CHECK-NEXT: introducing single enabled disjunction term {{.*}} bound to decl overload_filtering.(file).X.subscript(_:_:)
2933
_ = x[i, i]
3034
}
35+
36+
func testUnresolvedMember(i: Int) -> X {
37+
// CHECK: disabled disjunction term {{.*}} bound to decl overload_filtering.(file).X.init(_:)
38+
// CHECK-NEXT: disabled disjunction term {{.*}} bound to decl overload_filtering.(file).X.init(_:_:_:)
39+
// CHECK-NEXT: introducing single enabled disjunction term {{.*}} bound to decl overload_filtering.(file).X.init(_:_:)
40+
return .init(i, i)
41+
}

test/Constraints/patterns.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ switch staticMembers {
291291
case .init(0): break
292292
case .init(_): break // expected-error{{'_' can only appear in a pattern}}
293293
case .init(let x): break // expected-error{{cannot appear in an expression}}
294-
case .init(opt: 0): break // expected-error{{pattern cannot match values of type 'StaticMembers'}}
294+
case .init(opt: 0): break // expected-error{{value of optional type 'StaticMembers?' must be unwrapped to a value of type 'StaticMembers'}}
295+
// expected-note@-1{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
296+
// expected-note@-2{{coalesce using '??' to provide a default when the optional value contains 'nil'}}
295297

296298
case .prop: break
297299
// TODO: repeated error message

0 commit comments

Comments
 (0)