Skip to content

Commit b60c826

Browse files
authored
Merge pull request #38328 from xedin/rdar-79657350
[Diagnostics] Diagnose ambiguous solutions with warnings like regular…
2 parents 8a59c1e + d1e1278 commit b60c826

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,16 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
39113911
}
39123912
}
39133913

3914+
// If there either no fixes at all or all of the are warnings,
3915+
// let's diagnose this as regular ambiguity.
3916+
if (llvm::all_of(solutions, [](const Solution &solution) {
3917+
return llvm::all_of(solution.Fixes, [](const ConstraintFix *fix) {
3918+
return fix->isWarning();
3919+
});
3920+
})) {
3921+
return diagnoseAmbiguity(solutions);
3922+
}
3923+
39143924
// Algorithm is as follows:
39153925
//
39163926
// a. Aggregate all of the available fixes based on callee locator;

test/stdlib/UnsafePointerDiagnostics_warning.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ func unsafePointerInitEphemeralConversions() {
201201
// expected-note@-2 {{use the 'withUnsafeMutableBytes' method on Array in order to explicitly convert argument to buffer pointer valid for a defined scope}}
202202

203203
// FIXME: This is currently ambiguous.
204-
_ = OpaquePointer(&foo) // expected-error {{no exact matches in call to initializer}}
204+
_ = OpaquePointer(&foo) // expected-error {{ambiguous use of 'init(_:)'}}
205205

206206
// FIXME: This is currently ambiguous.
207-
_ = OpaquePointer(&arr) // expected-error {{no exact matches in call to initializer}}
207+
_ = OpaquePointer(&arr) // expected-error {{ambiguous use of 'init(_:)'}}
208208

209209
_ = OpaquePointer(arr) // expected-warning {{initialization of 'OpaquePointer' results in a dangling pointer}}
210210
// expected-note@-1 {{implicit argument conversion from '[Int]' to 'UnsafeRawPointer' produces a pointer valid only for the duration of the call to 'init(_:)'}}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
@resultBuilder
4+
struct MyResultBuilder {
5+
static func buildBlock(_ elements: Int...) -> Int { fatalError() }
6+
}
7+
8+
struct VariableDecl2 {
9+
init( // expected-note {{found this candidate}}
10+
paramClosure: () -> Int? = { nil },
11+
paramInt: Int,
12+
@MyResultBuilder paramResultBuilder: () -> Int? = { nil }
13+
) { fatalError() }
14+
15+
init( // expected-note {{found this candidate}}
16+
paramInt: Int,
17+
paramClosure: () -> Int? = { nil },
18+
@MyResultBuilder paramResultBuilder: () -> Int? = { nil }
19+
) {
20+
fatalError()
21+
}
22+
}
23+
24+
let buildable = VariableDecl2(paramInt: 1) { // expected-error {{ambiguous use of 'init'}}
25+
}

0 commit comments

Comments
 (0)