Skip to content

Commit 2de9053

Browse files
committed
[Diagnostics] Filter operators if all their arguments are holes
Restrict filtering in `simplifyAppliedOverloadsImpl` to disable overload set for operators only, because other calls e.g. regular functions or subscripts could be filtered on labels and are less overloaded. Filtering non-operator calls could also lead to incorrect diagnostics because first choice could have all sorts of different issues e.g. incorrect labels and number of parameters. Resolves: rdar://55369704
1 parent 9e159de commit 2de9053

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9630,10 +9630,13 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
96309630
return false;
96319631
});
96329632

9633-
// If all of the arguments are holes, let's disable all but one
9634-
// overload to make sure holes don't cause performance problems
9635-
// because hole could be bound to any type.
9636-
if (allHoles) {
9633+
// If this is an operator application and all of the arguments are holes,
9634+
// let's disable all but one overload to make sure holes don't cause
9635+
// performance problems because hole could be bound to any type.
9636+
//
9637+
// Non-operator calls are exempted because they have fewer overloads,
9638+
// and it's possible to filter them based on labels.
9639+
if (allHoles && isOperatorDisjunction(disjunction)) {
96379640
auto choices = disjunction->getNestedConstraints();
96389641
for (auto *choice : choices.slice(1))
96399642
choice->setDisabled();

test/Constraints/members.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,3 +725,13 @@ func rdar66891544() {
725725

726726
foo(.bar) // expected-error {{cannot infer contextual base in reference to member 'bar'}}
727727
}
728+
729+
// rdar://55369704 - extraneous diagnostics produced in combination with missing/misspelled members
730+
func rdar55369704() {
731+
struct S {
732+
}
733+
734+
func test(x: Int, s: S) {
735+
_ = x - Int(s.value) // expected-error {{value of type 'S' has no member 'value'}}
736+
}
737+
}

test/expr/unary/keypath/keypath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ func rdar74711236() {
10861086
// FIXME: Missing member reference is pattern needs a better diagnostic
10871087
if let type = context?.store { // expected-error {{type of expression is ambiguous without more context}}
10881088
// `isSupported` should be an invalid declaration to trigger a crash in `map(\.option)`
1089-
let isSupported = context!.supported().contains(type) // expected-error {{missing argument label 'where:' in call}} expected-error {{converting non-escaping value to '(Type) throws -> Bool' may allow it to escape}}
1089+
let isSupported = context!.supported().contains(type)
10901090
return (isSupported ? [type] : []).map(\.option)
10911091
// expected-error@-1 {{value of type 'Any' has no member 'option'}}
10921092
// expected-note@-2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}

0 commit comments

Comments
 (0)