-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
result should be true, with autofree result is false #7337
Comments
Related to: #4401 |
This might be a solution: #include <stdio.h>
#define bool int
#define false 0
#define true 1
int main(int argc, char argv[]) {
bool a = true;
bool _tmp_a = a;
bool _tmp_c;
if (true) {
a = false;
_tmp_c = true;
} else {
_tmp_c = false;
}
bool b = _tmp_a && _tmp_c;
printf("%s\n", b ? "true" : "false");
return 0;
} |
@yuyi98 Do you want to solve this? We also can get rid of the ternary generation completely if this works. |
@danieldaeschle Thanks! I'll try. But we cannot get rid of the ternary generation completely, because temporary variables generated before the if_expr statement can sometimes cause logic errors. |
The ternary stuff is not able to handle all cases, so we need to get rid of it. I think there are solutions to the temporary variable stuff but it's very hard to implement. |
@danieldaeschle The solution you give will be logic error in the following cases. fn main() {
mut a := true
b := if true {
a = false
true
} else {
false
} && a
println(b)
} |
But this is really an effective idea that needs to be perfected. |
@danieldaeschle Can we disable this usage? |
To me, disabling this usage would be a bad solution because in other languages it works. |
Ok, I see. |
@danieldaeschle Your solution can work for it. #include <stdio.h>
#define bool int
#define false 0
#define true 1
int main(int argc, char argv[]) {
bool a = true;
bool _tmp_c;
if (true) {
a = false;
_tmp_c = true;
} else {
_tmp_c = false;
}
bool _tmp_a = a;
bool b = _tmp_c && _tmp_a;
printf("%s\n", b ? "true" : "false");
return 0;
} |
Yes, but this needs a lot of forelooking |
What did you do?
What did you expect to see?
true
What did you see instead?
The text was updated successfully, but these errors were encountered: