Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitwise operator priority #89

Closed
mruz opened this issue Mar 15, 2020 · 4 comments
Closed

Bitwise operator priority #89

mruz opened this issue Mar 15, 2020 · 4 comments
Assignees

Comments

@mruz
Copy link

mruz commented Mar 15, 2020

php

$t = 1 & 1 << 7;
var_dump($t);

int(0)

zephir

int t;
int u = 1;
int v = 1;
let t = u & v << 7;
var_dump(t);
u = 1;
v = 1;
t = ((u & v) << 7);
ZEPHIR_INIT_VAR(&_10);
ZEPHIR_INIT_NVAR(&_10);
ZVAL_LONG(&_10, t);
zephir_var_dump(&_10);

int(128)

look at this:

php -r "var_dump((1 & 1) << 7);"
int(128)
php -r "var_dump(1 & 1 << 7);"
int(0)

so we shouldn't add parenthes t = ((u & v) << 7); here.

@sergeyklay
Copy link
Contributor

@dreamsxin Could you take a look by any chance?

@dreamsxin
Copy link
Contributor

@sergeyklay $t = 1 & 1 << 7; ===> $t = 1 & (1 << 7);
It needs to be adjusted according to the priority of the operator.

@sergeyklay
Copy link
Contributor

sergeyklay commented Mar 26, 2020

Thank you for the quick answer. I'll fix this one

@sergeyklay sergeyklay self-assigned this Mar 26, 2020
@sergeyklay sergeyklay transferred this issue from zephir-lang/zephir Mar 28, 2020
@sergeyklay
Copy link
Contributor

Fixed in development branch. Feel free to open a new issue if the problem appears again. Thank you for the bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants