Skip to content

Commit a892e57

Browse files
committed
[CSSimplify] Retry member lookup on an insufficiently resolved optional base in diagnostic mode
Re-introduce unsolved member constraint when optional object is a type variable or member until it's bound, otherwise it's impossible to tell whether unwrapped base would have a member or not.
1 parent e7a9bcb commit a892e57

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lib/Sema/CSSimplify.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11192,6 +11192,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
1119211192
functionRefInfo, locator,
1119311193
/*includeInaccessibleMembers*/ true);
1119411194

11195+
if (result.OverallResult == MemberLookupResult::Unsolved)
11196+
return formUnsolved();
11197+
1119511198
// If unwrapped type still couldn't find anything for a given name,
1119611199
// let's fallback to a "not such member" fix.
1119711200
if (result.ViableCandidates.empty() && result.UnviableCandidates.empty())

test/Constraints/result_builder_diags.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ enum Either<T,U> {
99
// expected-note @+1 2 {{struct 'TupleBuilder' declared here}}
1010
@resultBuilder struct TupleBuilder {
1111
static func buildBlock() -> () { }
12-
12+
1313
static func buildBlock<T1>(_ t1: T1) -> T1 {
1414
return t1
1515
}
16-
16+
1717
static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> (T1, T2) {
1818
return (t1, t2)
1919
}
20-
20+
2121
static func buildBlock<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3)
2222
-> (T1, T2, T3) {
2323
return (t1, t2, t3)
@@ -51,15 +51,15 @@ struct TupleBuilderWithoutIf { // expected-note 3{{struct 'TupleBuilderWithoutIf
5151
// expected-note@-2{{add 'buildEither(first:)' and 'buildEither(second:)' to the result builder 'TupleBuilderWithoutIf' to add support for 'if'-'else' and 'switch'}}
5252
// expected-note@-3{{add 'buildArray(_:)' to the result builder 'TupleBuilderWithoutIf' to add support for 'for'..'in' loops}}
5353
static func buildBlock() -> () { }
54-
54+
5555
static func buildBlock<T1>(_ t1: T1) -> T1 {
5656
return t1
5757
}
58-
58+
5959
static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> (T1, T2) {
6060
return (t1, t2)
6161
}
62-
62+
6363
static func buildBlock<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3)
6464
-> (T1, T2, T3) {
6565
return (t1, t2, t3)
@@ -152,7 +152,7 @@ func overloadedTuplify<T>(_ cond: Bool, @TupleBuilderWithoutIf body: (Bool) -> T
152152
func testOverloading(name: String) {
153153
let a1 = overloadedTuplify(true) { b in
154154
if b {
155-
"Hello, \(name)"
155+
"Hello, \(name)"
156156
}
157157
}
158158

@@ -171,7 +171,7 @@ func testOverloading(name: String) {
171171
$0 ? "Hello, \(name)" : "Goodbye"
172172
42
173173
if $0 {
174-
"Hello, \(name)"
174+
"Hello, \(name)"
175175
}
176176
}
177177
}
@@ -271,7 +271,7 @@ func erroneous_53751(x: Int) {
271271
if b {
272272
acceptInt(0) { }
273273
}
274-
}).domap(0) // expected-error{{value of type '()?' has no member 'domap'}}
274+
}).domap(0) // expected-error{{value of type 'Optional<()>' has no member 'domap'}}
275275
}
276276
}
277277

@@ -543,15 +543,15 @@ func testCaseVarTypes(e: E3) {
543543
@resultBuilder
544544
struct WrapperBuilder {
545545
static func buildBlock() -> () { }
546-
546+
547547
static func buildBlock<T1>(_ t1: T1) -> T1 {
548548
return t1
549549
}
550-
550+
551551
static func buildBlock<T1, T2>(_ t1: T1, _ t2: T2) -> (T1, T2) {
552552
return (t1, t2)
553553
}
554-
554+
555555
static func buildBlock<T1, T2, T3>(_ t1: T1, _ t2: T2, _ t3: T3)
556556
-> (T1, T2, T3) {
557557
return (t1, t2, t3)

0 commit comments

Comments
 (0)