-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FunC] Require parenthesis in tricky bitwise precedence cases
Example: "flags & 0xFF != 0" is equivalent to "flags & 1", most likely it's unexpected. Example: "a << 2 + 1" (equal to "a << 3", probably unexpected). The only way to suppress this error for the programmer is to use parenthesis.
- Loading branch information
1 parent
5867d52
commit 79721d2
Showing
10 changed files
with
189 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
int main(int flags) { | ||
return flags & 0xFF != 0; | ||
} | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr & has lower precedence than != | ||
@stderr Use parenthesis | ||
-} |
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,8 @@ | ||
int justTrue() { return true; } | ||
|
||
const a = justTrue() | 1 < 9; | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr | has lower precedence than < | ||
-} |
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,8 @@ | ||
int justTrue() { return true; } | ||
|
||
const a = justTrue() | (1 < 9) | justTrue() != true; | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr | has lower precedence than != | ||
-} |
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,6 @@ | ||
const a = (1) <=> (0) ^ 8; | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr ^ has lower precedence than <=> | ||
-} |
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,11 @@ | ||
const MAX_SLIPAGE = 100; | ||
|
||
_ main(int jetton_amount, int msg_value, int slippage) { | ||
if (0 == jetton_amount) | (msg_value == 0) | true | false | slippage > MAX_SLIPAGE { | ||
} | ||
} | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr | has lower precedence than > | ||
-} |
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,9 @@ | ||
_ main() { | ||
if ((1 == 1) | (2 == 2) & (3 == 3)) { | ||
} | ||
} | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr mixing | with & without parenthesis | ||
-} |
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,8 @@ | ||
_ main(int flags) { | ||
return flags << 1 + 32; | ||
} | ||
|
||
{- | ||
@compilation_should_fail | ||
@stderr << has lower precedence than + | ||
-} |
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
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