Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/Sema/CSRanking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ bool ConstraintSystem::worseThanBestSolution() const {

if (isDebugMode()) {
llvm::errs().indent(solverState->getCurrentIndent())
<< "(solution is worse than the best solution)\n";
<< "(solution " << CurrentScore << " is worse than the best solution "
<< solverState->BestScore <<")\n";
}

return true;
Expand Down
13 changes: 9 additions & 4 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11616,8 +11616,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
alreadyDiagnosed, locator);

auto instanceTy = baseObjTy->getMetatypeInstanceType();

auto impact = 4;
auto impact = 2;
// 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 @@ -11646,9 +11645,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
}

// Increasing the impact for missing member in any argument position so
// it doesn't affect situations where there are another fixes involved.
// it doesn't significantly pull away from situations with options.
if (getArgumentLocator(anchorExpr))
impact += 5;
impact += 1;
}

if (recordFix(fix, impact))
Expand Down Expand Up @@ -15650,6 +15649,12 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact,
if (auto impactScoreKind = fix->impact())
increaseScore(*impactScoreKind, fix->getLocator(), impact);

if (isDebugMode()) {
auto &log = llvm::errs();
log.indent(solverState ? solverState->getCurrentIndent() : 0)
<< "(fix has score " << impact << ")\n";
}

// If we've made the current solution worse than the best solution we've seen
// already, stop now.
if (worseThanBestSolution())
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/async_overload_filtering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var a: String? = nil
// CHECK: overload set choice binding $T0 := {{.*}}
// CHECK-NEXT: (considering: ({{.*}}) -> {{.*}} applicable fn {{.*}}
// CHECK: increasing 'sync-in-asynchronous' score by 1
// CHECK: solution is worse than the best solution
// CHECK: solution {{.*}} is worse than the best solution {{.*}}

filter_async {
Obj()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ test_combo(.genericFn(42)) // expected-error {{global function 'test_combo' requ

/* Invalid result types */

extension P { // expected-note 13 {{missing same-type requirement on 'Self'}} {{12-12= where Self == <#Type#>}}
extension P { // expected-note 8 {{missing same-type requirement on 'Self'}} {{12-12= where Self == <#Type#>}}
static func generic<T>(_: T) -> T { fatalError() }
static func genericWithReqs<T: Collection, Q>(_: T) -> Q where T.Element == Q { // expected-note 3 {{required by static method 'genericWithReqs' where 'T' = '()'}}
static func genericWithReqs<T: Collection & Q>(_: T) -> Q where T.Element == Q { // expected-note 4 {{required by static method 'genericWithReqs' where 'T' = '()'}} expected-note 5 {{where 'T' = '[any Q]'}}
fatalError()
}
}

extension P { // expected-note 6 {{missing same-type requirement on 'Self'}}
extension P { // expected-note 5 {{missing same-type requirement on 'Self'}}
static var invalidProp: Int { 42 }
static var selfProp: Self { fatalError() }
static func invalidMethod() -> Int { 42 }
Expand Down Expand Up @@ -211,12 +211,16 @@ _ = P.generic(42).other
_ = P.generic(S()) // expected-error {{static member 'generic' cannot be used on protocol metatype '(any P).Type'}}
_ = P.generic(S()).other // expected-error {{static member 'generic' cannot be used on protocol metatype '(any P).Type'}}
_ = P.generic(G<Int>()) // expected-error {{static member 'generic' cannot be used on protocol metatype '(any P).Type'}}
_ = P.genericWithReqs([S()]) // expected-error {{static member 'genericWithReqs' cannot be used on protocol metatype '(any P).Type'}}
_ = P.genericWithReqs([S()]) // expected-error {{static member 'genericWithReqs' cannot be used on protocol metatype '(any P).Type'}} expected-error {{static method 'genericWithReqs' requires that '[any Q]' conform to 'Q'}}
_ = P.genericWithReqs([42])
// expected-error@-1 {{static member 'genericWithReqs' cannot be used on protocol metatype '(any P).Type'}}
// expected-error@-2 {{cannot convert value of type 'Int' to expected element type 'any Q'}}
// expected-error@-3 {{static method 'genericWithReqs' requires that '[any Q]' conform to 'Q'}}
_ = P.genericWithReqs(())
// expected-error@-1 {{type '()' cannot conform to 'Collection'}} expected-note@-1 {{only concrete types such as structs, enums and classes can conform to protocols}}
// expected-error@-2 {{static member 'genericWithReqs' cannot be used on protocol metatype '(any P).Type'}}
// expected-error@-1 {{type '()' cannot conform to 'Collection'}}
// expected-error@-2 {{type '()' cannot conform to 'Q'}}
// expected-error@-3 {{static member 'genericWithReqs' cannot be used on protocol metatype '(any P).Type'}}
// expected-note@-4 2 {{only concrete types such as structs, enums and classes can conform to protocols}}
_ = P[q: ""]
// expected-error@-1 {{static member 'subscript' cannot be used on protocol metatype '(any P).Type'}}
_ = P[q: ""].other
Expand All @@ -227,6 +231,8 @@ test(.doesntExist) // expected-error {{type 'P' has no member 'doesntExist'}}
test(.doesnt.exist()) // expected-error {{type 'P' has no member 'doesnt'}}
test(.invalidProp)
// expected-error@-1 {{contextual member reference to static property 'invalidProp' requires 'Self' constraint in the protocol extension}}
test(.property.doesntExist)
// expected-error@-1 {{value of type 'S' has no member 'doesntExist'}}
test(.invalidProp.other)
// expected-error@-1 {{contextual member reference to static property 'invalidProp' requires 'Self' constraint in the protocol extension}}
// expected-error@-2 {{value of type 'Int' has no member 'other'}}
Expand All @@ -243,30 +249,47 @@ test(.generic(42).other)
test(.generic(S())) // expected-error {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test(.generic(G<Int>())) // expected-error {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test(.genericWithReqs([S()])) // expected-error {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-error@-1 {{static method 'genericWithReqs' requires that '[any Q]' conform to 'Q'}}
test(.genericWithReqs([S()]).doesntExist) // expected-error {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-error@-1 {{value of type 'any Q' has no member 'doesntExist'}}
// expected-error@-2 {{static method 'genericWithReqs' requires that '[any Q]' conform to 'Q'}}
test(.genericWithReqs([42]))
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-error@-2 {{static method 'genericWithReqs' requires that '[any Q]' conform to 'Q'}}
// expected-error@-3 {{cannot convert value of type 'Int' to expected element type 'any Q'}}
test(.genericWithReqs(()))
// expected-error@-1 {{type '()' cannot conform to 'Collection'}}
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
// expected-error@-2 {{type '()' cannot conform to 'Q'}}
// expected-error@-3 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-note@-4 2 {{only concrete types such as structs, enums and classes can conform to protocols}}

test_combo(.doesntExist) // expected-error {{reference to member 'doesntExist' cannot be resolved without a contextual type}}
test_combo(.doesnt.exist()) // expected-error {{reference to member 'doesnt' cannot be resolved without a contextual type}}
test_combo(.invalidProp)
// expected-error@-1 {{contextual member reference to static property 'invalidProp' requires 'Self' constraint in the protocol extension}}
test_combo(.invalidProp.doesntExist) //FIXME Should be reporting that Int has no doesntExist if P&Q lookup fixed
// expected-error@-1{{type 'Q' has no member 'invalidProp'}}
test_combo(.invalidMethod())
// expected-error@-1 {{contextual member reference to static method 'invalidMethod()' requires 'Self' constraint in the protocol extension}}
// expected-error@-1 {{failed to produce diagnostic for expression}}
// {{contextual member reference to static method 'invalidMethod()' requires 'Self' constraint in the protocol extension}}
test_combo(.generic(42))
// expected-error@-1 {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test_combo(.generic(S())) // expected-error {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test_combo(.generic(G<Int>())) // expected-error {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test_combo(.genericWithReqs([S()])) // expected-error {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
test_combo(.genericWithReqs([42]))
// expected-error@-1 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
test_combo(.genericWithReqs(()))
// expected-error@-1 {{type '()' cannot conform to 'Collection'}}
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
// expected-error@-3 {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-error@-1 {{failed to produce diagnostic for expression}}
// {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test_combo(.generic(S())) // expected-error {{failed to produce diagnostic for expression}}
// {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test_combo(.generic(G<Int>())) // expected-error {{failed to produce diagnostic for expression}}
// {{contextual member reference to static method 'generic' requires 'Self' constraint in the protocol extension}}
test_combo(.genericWithReqs([S()])) //FIXME error on Q membership an error on P&Q lookup, contextual error should occur
// {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-error@-2 {{type 'Q' has no member 'genericWithReqs'}}
test_combo(.genericWithReqs([42])) //FIXME error on Q membership an error on P&Q lookup, contextual error should occur
// {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}
// expected-error@-2 {{type 'Q' has no member 'genericWithReqs'}}
test_combo(.genericWithReqs(())) //FIXME error on Q membership an error on P&Q lookup, other errors should occur
// expected-error@-1{{type 'Q' has no member 'genericWithReqs'}}
// {{type '()' cannot conform to 'Collection'}}
// {{only concrete types such as structs, enums and classes can conform to protocols}}
// {{contextual member reference to static method 'genericWithReqs' requires 'Self' constraint in the protocol extension}}

protocol TestWithAssoc {
associatedtype U
Expand Down Expand Up @@ -381,4 +404,4 @@ test(.instanceProp)
// expected-error@-1 {{instance member 'instanceProp' cannot be used on type 'P'}}
test(.instanceProp2)
// expected-error@-1 {{instance member 'instanceProp2' cannot be used on type 'P'}}
// expected-error@-2 {{property 'instanceProp2' requires the types 'Self' and 'S' be equivalent}}
// expected-error@-2 {{property 'instanceProp2' requires the types 'Self' and 'S' be equivalent}}
2 changes: 1 addition & 1 deletion test/IDE/complete_closure_ambiguity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ foo {

// CONSTRAINTS: attempting disjunction choice {{.*}}:12:6
// CONSTRAINTS: increasing 'disfavored overload' score
// CONSTRAINTS: solution is worse than the best solution
// CONSTRAINTS: solution {{.*}} is worse than the best solution {{.*}}

// CONSTRAINTS-NOT-NOT: increasing 'hole'
20 changes: 20 additions & 0 deletions validation-test/Sema/SwiftUI/foreach_with_typo_property.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
// REQUIRES: objc_interop
// REQUIRES: OS=macosx
//

import SwiftUI
struct ContentView: View {
var foos: [F]

var body: some View {
ForEach(foos) { foo in
let name = foo.bat //expected-error{{value of type 'F' has no member 'bat'}}
}
}
}

struct F: Identifiable, Hashable {
var id: String { bar }
var bar: String // expected-note {{'bar' declared here}}
}