Skip to content

Commit 1917592

Browse files
committed
Disable '_move' contextual keyword absent -enable-experimental-move-only
Fixes rdar://100872195 ( error: 'move' can only be applied to lvalues error: Can not use feature when experimental move only is disabled!) Identifiers with a single underscore are not reserved for use by the language implementation. It is perfectly valid for a library to define its own '_move'. The contextual _move keyword should only be parse when it is followed by an lvalue, so should *not* conflict with user-defined '_move' functions. https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md#source-compatibility
1 parent 6105077 commit 1917592

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
432432
return sub;
433433
}
434434

435-
if (Tok.isContextualKeyword("_move")) {
435+
if (Context.LangOpts.hasFeature(Feature::MoveOnly)
436+
&& Tok.isContextualKeyword("_move")) {
436437
Tok.setKind(tok::contextual_keyword);
437438
SourceLoc awaitLoc = consumeToken();
438439
ParserResult<Expr> sub =

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
409409

410410
void checkMoveExpr(MoveExpr *moveExpr) {
411411
// Make sure the MoveOnly feature is set. If not, error.
412+
// This should not currently be reached because the parse should ignore
413+
// the _move keyword unless the feature flag is set.
412414
if (!Ctx.LangOpts.hasFeature(Feature::MoveOnly)) {
413415
auto error =
414416
diag::experimental_moveonly_feature_can_only_be_used_when_enabled;

test/Parse/move_func_decl.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking
2+
3+
// rdar://100872195 (error: 'move' can only be applied to lvalues , error: Can not use feature when experimental move only is disabled!)
4+
//
5+
// Identifiers with a single underscore are not reserved for use by the language implementation. It is perfectly valid for a library to define its own '_move'.
6+
// The contextual _move keyword should only be parse when it is followed by an lvalue, so should *not* conflict with user-defined '_move' functions.
7+
// https://github.com/apple/swift-evolution/blob/main/proposals/0366-move-function.md#source-compatibility
8+
9+
func _move<T>(t: T) -> T { return t }
10+
11+
func testUserMove() {
12+
let t = String()
13+
let _ = _move(t: t)
14+
}

0 commit comments

Comments
 (0)