Deprecate the use of "a=b" for non-temporary assignment in 0.15.

It is still the syntax for temporary assignment; only using it as a standalone
command is deprecated.
This commit is contained in:
Qi Xiao 2021-01-19 23:21:38 +00:00
parent fbfbef8531
commit 37c3c0b0de
3 changed files with 14 additions and 1 deletions

View File

@ -25,6 +25,12 @@ This is the draft release notes for 0.15.0, scheduled to be released on
The following deprecated features trigger a warning whenever the code is parsed
or compiled, even if it is not executed:
- Using the syntax of temporary assignment (`var=value`) for non-temporary
assignment is now deprecated. The syntax is still valid for temporary
assignment. For example, using `foo=bar` as a standalone command is
deprecated, but using it as part of command, like `foo=bar ls`, is not
deprecated.
- The `chr` command is now deprecated. Use `str:from-codepoints` instead.
- The `ord` command is now deprecated. Use `str:to-codepoints` instead.

View File

@ -161,7 +161,9 @@ func (cp *compiler) formOp(n *parse.Form) effectOp {
if len(n.Assignments) > 0 {
assignmentOps = cp.assignmentOps(n.Assignments)
if n.Head == nil {
// Permanent assignment.
// Using the syntax of temporary assignment for non-temporary
// assignment. Still supported as of 0.15 but deprecated.
cp.deprecate(n, `using the syntax of temporary assignment for non-temporary assignment is deprecated; use "var" or "set" instead`, 15)
return seqOp{assignmentOps}
}
for _, a := range n.Assignments {

View File

@ -69,6 +69,11 @@ func TestCommand(t *testing.T) {
)
}
func TestCommand_DeprecateUsingTemporaryAssignmentForNonTemporaryAssignment(t *testing.T) {
testCompileTimeDeprecation(t, "foo=bar", `using the syntax of temporary assignment for non-temporary assignment is deprecated; use "var" or "set" instead`, 15)
}
func TestCommand_Special(t *testing.T) {
Test(t,
// Regression test for #1204; ensures that the arguments of special