Skip to content

Commit 97f284a

Browse files
committed
[CSSimplify] Don't increase impact if member doesn't exist on Any/AnyObject
`Any` used to be the type used to indicate placeholders before and that's reflected in the score of the `DefineMemberBasedOnUse`, this is no longer the same and the impact increase should be dropped.
1 parent 854298a commit 97f284a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11031,9 +11031,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
1103111031
impact += 10;
1103211032
}
1103311033

11034-
if (instanceTy->isAny() || instanceTy->isAnyObject())
11035-
impact += 5;
11036-
1103711034
auto *anchorExpr = getAsExpr(locator->getAnchor());
1103811035
if (anchorExpr) {
1103911036
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(anchorExpr)) {

test/Constraints/members.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,14 @@ do {
826826
// expected-error@-1 {{value of type 'any BinaryInteger' has no member 'op'}}
827827
}
828828
}
829+
830+
do {
831+
func test<T>(_: T) -> T? { nil }
832+
func test<U>(_: U) -> Int { 0 }
833+
834+
func compute(x: Any) {
835+
test(x)!.unknown()
836+
// expected-error@-1 {{value of type 'Any' has no member 'unknown'}}
837+
// expected-note@-2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
838+
}
839+
}

0 commit comments

Comments
 (0)