Skip to content

[CSSimplify] Increment impact for DefineMemberBasedOnUse when base type is any function type #29795

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 2 commits into from
Feb 13, 2020
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
7 changes: 7 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6322,6 +6322,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
// not a match in this case.
auto impact =
locator->findLast<LocatorPathElt::UnresolvedMember>() ? 2 : 1;

// Impact is higher if the the base type is any function type
// because function types can't have any members other than self
if (baseObjTy->is<AnyFunctionType>()) {
impact += 10;
}

if (recordFix(fix, impact))
return SolutionKind::Error;

Expand Down
20 changes: 20 additions & 0 deletions test/Constraints/diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1385,3 +1385,23 @@ class ClassWithPropContainingSetter {
set { return 1 } // expected-error {{unexpected non-void return value in void function}}
}
}

// https://bugs.swift.org/browse/SR-11964
struct Rect {
let width: Int
let height: Int
}

struct Frame {
func rect(width: Int, height: Int) -> Rect {
Rect(width: width, height: height)
}

let rect: Rect
}

func foo(frame: Frame) {
frame.rect.width + 10.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int)}}

}