Skip to content

[Sema] Raise impact of DefineMemberBasedOnUse to match RemoveInvalidCall #74692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11115,7 +11115,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(

auto instanceTy = baseObjTy->getMetatypeInstanceType();

auto impact = 2;
auto impact = 4;
// Impact is higher if the base type is any function type
// because function types can't have any members other than self
if (instanceTy->is<AnyFunctionType>()) {
Expand Down Expand Up @@ -13392,7 +13392,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
// Let's make this fix as high impact so if there is a function or member
// overload with e.g. argument-to-parameter type mismatches it would take
// a higher priority.
return recordFix(fix, /*impact=*/10) ? SolutionKind::Error
return recordFix(fix, /*impact=*/3) ? SolutionKind::Error
: SolutionKind::Solved;
}

Expand Down
29 changes: 17 additions & 12 deletions test/Constraints/diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,7 @@ func rdar20142523() {
// <rdar://problem/21080030> Bad diagnostic for invalid method call in boolean expression: (_, ExpressibleByIntegerLiteral)' is not convertible to 'ExpressibleByIntegerLiteral
func rdar21080030() {
var s = "Hello"
// https://github.com/apple/swift/issues/50141
// This should be 'cannot_call_non_function_value'.
if s.count() == 0 {}
// expected-error@-1 {{generic parameter 'E' could not be inferred}}
// expected-error@-2 {{missing argument for parameter 'where' in call}}
if s.count() == 0 {} // expected-error {{cannot call value of non-function type 'Int'}}
}

// <rdar://problem/21248136> QoI: problem with return type inference mis-diagnosed as invalid arguments
Expand Down Expand Up @@ -1537,9 +1533,7 @@ func issue63746() {
}

func rdar86611718(list: [Int]) {
String(list.count())
// expected-error@-1 {{missing argument for parameter 'where' in call}}
// expected-error@-2 {{generic parameter 'E' could not be inferred}}
String(list.count()) // expected-error {{cannot call value of non-function type 'Int'}}
}

// rdar://108977234 - failed to produce diagnostic when argument to AnyHashable parameter doesn't conform to Hashable protocol
Expand All @@ -1558,17 +1552,28 @@ func testNilCoalescingOperatorRemoveFix() {
let _ = "" /* This is a comment */ ?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{13-43=}}

let _ = "" // This is a comment
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1560:13-1561:10=}}
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1554:13-1555:10=}}

let _ = "" // This is a comment
/*
* The blank line below is part of the test case, do not delete it
*/
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1563:13-1567:10=}}
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1557:13-1561:10=}}

if ("" ?? // This is a comment // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{9-1570:9=}}
if ("" ?? // This is a comment // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{9-1564:9=}}
"").isEmpty {}

if ("" // This is a comment
?? "").isEmpty {} // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1572:9-1573:12=}}
?? "").isEmpty {} // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1566:9-1567:12=}}
}

// https://github.com/apple/swift/issues/74617
struct Foo_74617 {
public var bar: Float { 123 }
public static func + (lhs: Self, rhs: Self) -> Self { Self() }
}
func testAddMemberVsRemoveCall() {
let a = Foo_74617()
let b = Foo_74617()
let c = (a + b).bar() // expected-error {{cannot call value of non-function type 'Float'}} {{22-24=}}
}