Skip to content

Commit 535becc

Browse files
committed
---
yaml --- r: 323446 b: refs/heads/tensorflow-next c: 5712276 h: refs/heads/master
1 parent 652345f commit 535becc

File tree

8 files changed

+40
-130
lines changed

8 files changed

+40
-130
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,4 @@ refs/heads/master-rebranch: 86e95c23aa0d37f24ec138b7853146c1cead2e40
14611461
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14621462
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14631463
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec
1464-
refs/heads/tensorflow-next: 73c9a920c98f8e68bb24a1811c43e44c5da1b328
1464+
refs/heads/tensorflow-next: 571227677ca32d46710c42a09a219f42e5eaa15b

branches/tensorflow-next/lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,117 +3057,6 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
30573057
return false;
30583058
}
30593059

3060-
// It is a somewhat common error to try to access an instance method as a
3061-
// curried member on the type, instead of using an instance, e.g. the user
3062-
// wrote:
3063-
//
3064-
// Foo.doThing(42, b: 19)
3065-
//
3066-
// instead of:
3067-
//
3068-
// myFoo.doThing(42, b: 19)
3069-
//
3070-
// Check for this situation and handle it gracefully.
3071-
static bool
3072-
diagnoseInstanceMethodAsCurriedMemberOnType(CalleeCandidateInfo &CCI,
3073-
Expr *fnExpr, Expr *argExpr) {
3074-
for (auto &candidate : CCI.candidates) {
3075-
if (!candidate.hasParameters())
3076-
return false;
3077-
3078-
auto *decl = candidate.getDecl();
3079-
if (!decl)
3080-
return false;
3081-
3082-
// If this is an exact match at the level 1 of the parameters, but
3083-
// there is still something wrong with the expression nevertheless
3084-
// it might be worth while to check if it's instance method as curried
3085-
// member of type problem.
3086-
if (CCI.closeness == CC_ExactMatch &&
3087-
(decl->isInstanceMember() && candidate.skipCurriedSelf))
3088-
continue;
3089-
3090-
auto params = candidate.getParameters();
3091-
// If one of the candidates is an instance method with a single parameter
3092-
// at the level 0, this might be viable situation for calling instance
3093-
// method as curried member of type problem.
3094-
if (params.size() != 1 || !decl->isInstanceMember() ||
3095-
candidate.skipCurriedSelf)
3096-
return false;
3097-
}
3098-
3099-
auto &TC = CCI.CS.TC;
3100-
3101-
if (auto UDE = dyn_cast<UnresolvedDotExpr>(fnExpr)) {
3102-
auto baseExpr = UDE->getBase();
3103-
auto baseType = CCI.CS.getType(baseExpr);
3104-
if (auto *MT = baseType->getAs<MetatypeType>()) {
3105-
auto DC = CCI.CS.DC;
3106-
auto instanceType = MT->getInstanceType();
3107-
3108-
// If the base is an implicit self type reference, and we're in a
3109-
// an initializer, then the user wrote something like:
3110-
//
3111-
// class Foo { let val = initFn() }
3112-
// or
3113-
// class Bar { func something(x: Int = initFn()) }
3114-
//
3115-
// which runs in type context, not instance context. Produce a tailored
3116-
// diagnostic since this comes up and is otherwise non-obvious what is
3117-
// going on.
3118-
if (baseExpr->isImplicit() && isa<Initializer>(DC)) {
3119-
auto *TypeDC = DC->getParent();
3120-
bool propertyInitializer = true;
3121-
// If the parent context is not a type context, we expect it
3122-
// to be a defaulted parameter in a function declaration.
3123-
if (!TypeDC->isTypeContext()) {
3124-
assert(TypeDC->getContextKind() ==
3125-
DeclContextKind::AbstractFunctionDecl &&
3126-
"Expected function decl context for initializer!");
3127-
TypeDC = TypeDC->getParent();
3128-
propertyInitializer = false;
3129-
}
3130-
assert(TypeDC->isTypeContext() && "Expected type decl context!");
3131-
3132-
if (TypeDC->getSelfNominalTypeDecl() == instanceType->getAnyNominal()) {
3133-
if (propertyInitializer)
3134-
TC.diagnose(UDE->getLoc(), diag::instance_member_in_initializer,
3135-
UDE->getName());
3136-
else
3137-
TC.diagnose(UDE->getLoc(),
3138-
diag::instance_member_in_default_parameter,
3139-
UDE->getName());
3140-
return true;
3141-
}
3142-
}
3143-
3144-
// If this is a situation like this `self.foo(A())()` and self != A
3145-
// let's say that `self` is not convertible to A.
3146-
if (auto nominalType = CCI.CS.getType(argExpr)->getAs<NominalType>()) {
3147-
if (!instanceType->isEqual(nominalType)) {
3148-
TC.diagnose(argExpr->getStartLoc(), diag::types_not_convertible,
3149-
false, nominalType, instanceType);
3150-
return true;
3151-
}
3152-
}
3153-
3154-
// Otherwise, complain about use of instance value on type.
3155-
if (isa<TypeExpr>(baseExpr)) {
3156-
TC.diagnose(UDE->getLoc(), diag::instance_member_use_on_type,
3157-
instanceType, UDE->getName())
3158-
.highlight(baseExpr->getSourceRange());
3159-
} else {
3160-
TC.diagnose(UDE->getLoc(), diag::could_not_use_instance_member_on_type,
3161-
instanceType, UDE->getName(), instanceType, false)
3162-
.highlight(baseExpr->getSourceRange());
3163-
}
3164-
return true;
3165-
}
3166-
}
3167-
3168-
return false;
3169-
}
3170-
31713060
static bool diagnoseTupleParameterMismatch(CalleeCandidateInfo &CCI,
31723061
ArrayRef<AnyFunctionType::Param> params,
31733062
ArrayRef<AnyFunctionType::Param> args,
@@ -3786,9 +3675,6 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
37863675
if (diagnoseImplicitSelfErrors(fnExpr, argExpr, CCI, argLabels))
37873676
return true;
37883677

3789-
if (diagnoseInstanceMethodAsCurriedMemberOnType(CCI, fnExpr, argExpr))
3790-
return true;
3791-
37923678
// Do all the stuff that we only have implemented when there is a single
37933679
// candidate.
37943680
if (diagnoseSingleCandidateFailures(CCI, fnExpr, argExpr, argLabels))

branches/tensorflow-next/lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,10 +2382,13 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
23822382
return true;
23832383
}
23842384

2385-
if (isa<TypeExpr>(getRawAnchor())) {
2386-
emitDiagnostic(loc, diag::instance_member_use_on_type, instanceTy, Name)
2387-
.highlight(getRawAnchor()->getSourceRange());
2388-
return true;
2385+
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(getRawAnchor())) {
2386+
auto *baseExpr = UDE->getBase();
2387+
if (isa<TypeExpr>(baseExpr)) {
2388+
emitDiagnostic(loc, diag::instance_member_use_on_type, instanceTy, Name)
2389+
.highlight(baseExpr->getSourceRange());
2390+
return true;
2391+
}
23892392
}
23902393

23912394
// Just emit a generic "instance member cannot be used" error

branches/tensorflow-next/lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,9 +4214,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
42144214

42154215
// See if we have an instance method, instance member or static method,
42164216
// and check if it can be accessed on our base type.
4217+
42174218
if (decl->isInstanceMember()) {
4218-
if ((isa<FuncDecl>(decl) && !hasInstanceMethods) ||
4219-
(!isa<FuncDecl>(decl) && !hasInstanceMembers)) {
4219+
if (baseObjTy->is<AnyMetatypeType>()) {
42204220
// `AnyObject` has special semantics, so let's just let it be.
42214221
// Otherwise adjust base type and reference kind to make it
42224222
// look as if lookup was done on the instance, that helps
@@ -4225,8 +4225,20 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
42254225
? candidate
42264226
: OverloadChoice(instanceTy, decl,
42274227
FunctionRefKind::SingleApply);
4228+
// If this is an instance member referenced from metatype
4229+
// let's add unviable result to the set because it could be
4230+
// either curried reference or an invalid call.
4231+
//
4232+
// New candidate shouldn't affect performance because such
4233+
// choice would only be attempted when solver is in diagnostic mode.
42284234
result.addUnviable(choice, MemberLookupResult::UR_InstanceMemberOnType);
4229-
return;
4235+
4236+
bool invalidMethodRef = isa<FuncDecl>(decl) && !hasInstanceMethods;
4237+
bool invalidMemberRef = !isa<FuncDecl>(decl) && !hasInstanceMembers;
4238+
// If this is definitely an invalid way to reference a method or member
4239+
// on the metatype, let's stop here.
4240+
if (invalidMethodRef || invalidMemberRef)
4241+
return;
42304242
}
42314243

42324244
// If the underlying type of a typealias is fully concrete, it is legal

branches/tensorflow-next/test/ClangImporter/objc_parse.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ func classMethods(_ b: B, other: NSObject) {
7474
// Both class and instance methods exist.
7575
B.description()
7676
B.instanceTakesObjectClassTakesFloat(2.0)
77-
B.instanceTakesObjectClassTakesFloat(other) // expected-error{{cannot convert value of type 'NSObject' to expected argument type 'Float'}}
77+
// TODO(diagnostics): Once argument/parameter conversion diagnostics are implemented we should be able to
78+
// diagnose this as failed conversion from NSObject to Float, but right now the problem is that there
79+
// exists another overload `instanceTakesObjectClassTakesFloat: (Any?) -> Void` which makes this invocation
80+
// type-check iff base is an instance of `B`.
81+
B.instanceTakesObjectClassTakesFloat(other)
82+
// expected-error@-1 {{instance member 'instanceTakesObjectClassTakesFloat' cannot be used on type 'B'; did you mean to use a value of this type instead?}}
7883

7984
// Call an instance method of NSObject.
8085
var c: AnyClass = B.myClass() // no-warning
@@ -347,7 +352,7 @@ func testDynamicSelf(_ queen: Bee, wobbler: NSWobbling) {
347352
// class itself.
348353
// FIXME: This should be accepted.
349354
let baseClass: ObjCParseExtras.Base.Type = ObjCParseExtras.Base.returnMyself()
350-
// expected-error@-1 {{instance member 'returnMyself' cannot be used on type 'Base'}}
355+
// expected-error@-1 {{missing argument for parameter #1 in call}}
351356
}
352357

353358
func testRepeatedProtocolAdoption(_ w: NSWindow) {

branches/tensorflow-next/test/Constraints/diagnostics.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,12 @@ c.method2(1.0)(2.0) // expected-error {{cannot convert value of type 'Double' to
364364
CurriedClass.method1(c)()
365365
_ = CurriedClass.method1(c)
366366
CurriedClass.method1(c)(1) // expected-error {{argument passed to call that takes no arguments}}
367-
CurriedClass.method1(2.0)(1) // expected-error {{instance member 'method1' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
367+
CurriedClass.method1(2.0)(1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'CurriedClass'}}
368368

369369
CurriedClass.method2(c)(32)(b: 1) // expected-error{{extraneous argument label 'b:' in call}}
370370
_ = CurriedClass.method2(c)
371371
_ = CurriedClass.method2(c)(32)
372-
_ = CurriedClass.method2(1,2) // expected-error {{instance member 'method2' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
372+
_ = CurriedClass.method2(1,2) // expected-error {{extra argument in call}}
373373
CurriedClass.method2(c)(1.0)(b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
374374
CurriedClass.method2(c)(1)(1.0) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
375375
CurriedClass.method2(c)(2)(c: 1.0) // expected-error {{extraneous argument label 'c:'}}
@@ -379,6 +379,7 @@ _ = CurriedClass.method3(c)
379379
_ = CurriedClass.method3(c)(1, 2) // expected-error {{missing argument label 'b:' in call}} {{32-32=b: }}
380380
_ = CurriedClass.method3(c)(1, b: 2)(32) // expected-error {{cannot call value of non-function type '()'}}
381381
_ = CurriedClass.method3(1, 2) // expected-error {{instance member 'method3' cannot be used on type 'CurriedClass'; did you mean to use a value of this type instead?}}
382+
// expected-error@-1 {{missing argument label 'b:' in call}}
382383
CurriedClass.method3(c)(1.0, b: 1) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
383384
CurriedClass.method3(c)(1) // expected-error {{missing argument for parameter 'b' in call}}
384385
CurriedClass.method3(c)(c: 1.0) // expected-error {{missing argument for parameter #1 in call}}

branches/tensorflow-next/test/Constraints/members.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class A {}
522522

523523
enum B {
524524
static func foo() {
525-
bar(A()) // expected-error {{'A' is not convertible to 'B'}}
525+
bar(A()) // expected-error {{instance member 'bar' cannot be used on type 'B'}}
526526
}
527527

528528
func bar(_: A) {}

branches/tensorflow-next/test/NameBinding/name_lookup.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ThisBase1 {
1313
}
1414

1515
func baseFunc0() {}
16-
func baseFunc1(_ a: Int) {}
16+
func baseFunc1(_ a: Int) {} // expected-note 2 {{found this candidate}}
1717

1818
subscript(i: Int) -> Double {
1919
get {
@@ -227,7 +227,10 @@ class ThisDerived1 : ThisBase1 {
227227

228228
self.baseFunc0(ThisDerived1())()
229229
self.baseFunc1(42) // expected-error {{instance member 'baseFunc1' cannot be used on type 'ThisDerived1'}}
230-
self.baseFunc1(ThisBase1())(42) // expected-error {{'ThisBase1' is not convertible to 'ThisDerived1'}}
230+
// TODO(diagnostics): Constraint system is not currently set up to handle this case because overload choice
231+
// would have a type of `(A) -> (Int) -> Void` which then gets fixed up to be `(B) -> (Int) -> Void` when
232+
// the choice is attempted.
233+
self.baseFunc1(ThisBase1())(42) // expected-error {{ambiguous reference to member 'baseFunc1'}}
231234
self.baseFunc1(ThisDerived1())(42)
232235
self[0] = 42.0 // expected-error {{instance member 'subscript' cannot be used on type 'ThisDerived1'}}
233236
self.baseStaticVar = 42
@@ -253,7 +256,7 @@ class ThisDerived1 : ThisBase1 {
253256
self.derivedInstanceVar = 42 // expected-error {{member 'derivedInstanceVar' cannot be used on type 'ThisDerived1'}}
254257
self.derivedProp = 42 // expected-error {{member 'derivedProp' cannot be used on type 'ThisDerived1'}}
255258
self.derivedFunc0() // expected-error {{instance member 'derivedFunc0' cannot be used on type 'ThisDerived1'}}
256-
self.derivedFunc0(ThisBase1())() // expected-error {{'ThisBase1' is not convertible to 'ThisDerived1'}}
259+
self.derivedFunc0(ThisBase1())() // expected-error {{cannot convert value of type 'ThisBase1' to expected argument type 'ThisDerived1'}}
257260
self.derivedFunc0(ThisDerived1())()
258261
self.derivedStaticVar = 42
259262
self.derivedStaticProp = 42

0 commit comments

Comments
 (0)