mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support arbitrary postfix operators in key paths.
This commit is contained in:
@@ -2531,11 +2531,11 @@ void PreCheckTarget::resolveKeyPathExpr(KeyPathExpr *KPE) {
|
||||
(void)outermostExpr;
|
||||
assert(OEE == outermostExpr);
|
||||
expr = OEE->getSubExpr();
|
||||
} else if (auto AE = dyn_cast<ApplyExpr>(expr)) {
|
||||
} else if (auto CE = dyn_cast<CallExpr>(expr)) {
|
||||
// foo(), foo(val value: Int) or unapplied foo
|
||||
components.push_back(KeyPathExpr::Component::forUnresolvedApply(
|
||||
getASTContext(), AE->getArgs()));
|
||||
expr = AE->getFn();
|
||||
getASTContext(), CE->getArgs()));
|
||||
expr = CE->getFn();
|
||||
} else {
|
||||
if (emitErrors) {
|
||||
// \(<expr>) may be an attempt to write a string interpolation outside
|
||||
|
||||
@@ -407,7 +407,6 @@ _ = /\()/
|
||||
// expected-error@-1 {{'/' is not a prefix unary operator}}
|
||||
// expected-error@-2 {{'/' is not a postfix unary operator}}
|
||||
// expected-error@-3 {{invalid component of Swift key path}}
|
||||
// expected-error@-4 {{type of expression is ambiguous without a type annotation}}
|
||||
|
||||
do {
|
||||
let _: Regex = (/whatever\)/
|
||||
|
||||
@@ -46,3 +46,16 @@ func f_56996() {
|
||||
_ = \Int.byteSwapped.signum() // expected-error {{key path cannot refer to instance method 'signum()'}}
|
||||
_ = \Int.byteSwapped.init() // expected-error {{key path cannot refer to initializer 'init()'}}
|
||||
}
|
||||
|
||||
postfix operator ^
|
||||
postfix func ^ <T>(_ x: T) -> T { x }
|
||||
|
||||
func unsupportedOperator() {
|
||||
struct S {
|
||||
var x: Int
|
||||
}
|
||||
_ = \.^ // expected-error {{invalid component of Swift key path}}
|
||||
_ = \S^ // expected-error {{invalid component of Swift key path}}
|
||||
_ = \S.x^ // expected-error {{invalid component of Swift key path}}
|
||||
_ = \.x^ // expected-error {{invalid component of Swift key path}}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
// {"signature":"(anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*)"}
|
||||
// RUN: not %target-swift-frontend -typecheck %s
|
||||
\.+=
|
||||
Reference in New Issue
Block a user