Skip to content

Commit 2274e17

Browse files
committed
[CSFix] Allow diagnosing the same out-of-order argument in ambiguity cases
Is the same argument is out-of-order in multiple solutions, let's diagnose it as if there was no ambiguity. Resolves: SR-14093 Resolves: rdar://73600328
1 parent 1b7795b commit 2274e17

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

include/swift/Sema/CSFix.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,11 +1394,19 @@ class MoveOutOfOrderArgument final : public ConstraintFix {
13941394

13951395
bool diagnose(const Solution &solution, bool asNote = false) const override;
13961396

1397+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override;
1398+
1399+
bool isEqual(const ConstraintFix *other) const;
1400+
13971401
static MoveOutOfOrderArgument *create(ConstraintSystem &cs,
13981402
unsigned argIdx,
13991403
unsigned prevArgIdx,
14001404
ArrayRef<ParamBinding> bindings,
14011405
ConstraintLocator *locator);
1406+
1407+
static bool classof(const ConstraintFix *fix) {
1408+
return fix->getKind() == FixKind::MoveOutOfOrderArgument;
1409+
}
14021410
};
14031411

14041412
class AllowInaccessibleMember final : public AllowInvalidMemberRef {

lib/Sema/CSFix.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,29 @@ bool MoveOutOfOrderArgument::diagnose(const Solution &solution,
865865
return failure.diagnose(asNote);
866866
}
867867

868+
bool MoveOutOfOrderArgument::diagnoseForAmbiguity(
869+
CommonFixesArray commonFixes) const {
870+
auto *primaryFix =
871+
commonFixes.front().second->getAs<MoveOutOfOrderArgument>();
872+
assert(primaryFix);
873+
874+
if (llvm::all_of(
875+
commonFixes,
876+
[&primaryFix](
877+
const std::pair<const Solution *, const ConstraintFix *> &entry) {
878+
return primaryFix->isEqual(entry.second);
879+
}))
880+
return diagnose(*commonFixes.front().first);
881+
882+
return false;
883+
}
884+
885+
bool MoveOutOfOrderArgument::isEqual(const ConstraintFix *other) const {
886+
auto OoOFix = other->getAs<MoveOutOfOrderArgument>();
887+
return OoOFix ? ArgIdx == OoOFix->ArgIdx && PrevArgIdx == OoOFix->PrevArgIdx
888+
: false;
889+
}
890+
868891
MoveOutOfOrderArgument *MoveOutOfOrderArgument::create(
869892
ConstraintSystem &cs, unsigned argIdx, unsigned prevArgIdx,
870893
ArrayRef<ParamBinding> bindings, ConstraintLocator *locator) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift -target x86_64-apple-macosx10.15 -swift-version 5
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
import Foundation
8+
9+
struct ContentView: View {
10+
@State private var date = Date()
11+
12+
var body: some View {
13+
Group {
14+
DatePicker("Enter a date", selection: $date, displayedComponents: .date, in: Date())
15+
// expected-error@-1 {{argument 'in' must precede argument 'displayedComponents'}} {{78-90=}} {{52-52=in: Date(), }}
16+
DatePicker("Enter a date", selection: $date, displayedComponents: .date, in: Date() ... Date().addingTimeInterval(100))
17+
// expected-error@-1 {{argument 'in' must precede argument 'displayedComponents'}} {{78-125=}} {{52-52=in: Date() ... Date().addingTimeInterval(100), }}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)