-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: self-increment and self-decrement operators return wrong values …
…in the return statement Signed-off-by: ganjing <[email protected]>
- Loading branch information
1 parent
e3976c1
commit 6b025f4
Showing
3 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
let globalIndex: number = 3 | ||
function increasePre(): number { | ||
return ++globalIndex; | ||
} | ||
function increasePost(): number { | ||
return globalIndex++; | ||
} | ||
function decreasePre(): number { | ||
return --globalIndex; | ||
} | ||
function decreasePost(): number { | ||
return globalIndex--; | ||
} | ||
|
||
function plusplusTest() { | ||
let ret = increasePre(); | ||
console.log(ret); | ||
console.log(globalIndex); | ||
|
||
ret = increasePost(); | ||
console.log(ret); | ||
console.log(globalIndex); | ||
|
||
let localIndex = 0; | ||
console.log(localIndex++); | ||
console.log(++localIndex); | ||
} | ||
|
||
function minusminusTest() { | ||
let ret = decreasePre(); | ||
console.log(ret); | ||
console.log(globalIndex); | ||
|
||
ret = decreasePost(); | ||
console.log(ret); | ||
console.log(globalIndex); | ||
|
||
let localIndex = 2; | ||
console.log(localIndex--); | ||
console.log(--localIndex); | ||
} | ||
|
||
function exclamationTest() { | ||
const f = 0; | ||
console.log(!f); | ||
|
||
const t = 1; | ||
console.log(!t); | ||
} | ||
|
||
function minusTest() { | ||
const a = 1; | ||
console.log(-a); | ||
|
||
const b = -2; | ||
console.log(-b); | ||
} | ||
|
||
export function test() { | ||
plusplusTest(); | ||
minusminusTest(); | ||
exclamationTest(); | ||
minusTest(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters