diff options
author | Miguel de Icaza <miguel@gnome.org> | 2001-11-22 23:36:17 +0300 |
---|---|---|
committer | Miguel de Icaza <miguel@gnome.org> | 2001-11-22 23:36:17 +0300 |
commit | 3b121439a9de9e7b796fab4685dad280bfee82ef (patch) | |
tree | ac5064a79a597284321beeff9f1ff65b5af2d827 /mcs/tests/test-47.cs | |
parent | b2f78e38cf8ce633fd40a454d31e10548b093600 (diff) |
2001-11-22 Miguel de Icaza <miguel@ximian.com>
* statement.cs (If.Emit): Fix a bug that generated incorrect code
on If. Basically, we have to return `true' (ie, we do return to
our caller) only if both branches of the if return.
* expression.cs (Binary.Emit): LogicalOr and LogicalAnd are
short-circuit operators, handle them as short circuit operators.
svn path=/trunk/mcs/; revision=1427
Diffstat (limited to 'mcs/tests/test-47.cs')
-rwxr-xr-x | mcs/tests/test-47.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/mcs/tests/test-47.cs b/mcs/tests/test-47.cs new file mode 100755 index 00000000000..c269d0b6c71 --- /dev/null +++ b/mcs/tests/test-47.cs @@ -0,0 +1,95 @@ +// +// Short-circuit evaluation tests +// +using System; + +class X { + + static int t_count = 0; + static int f_count = 0; + + static bool f () + { + Console.WriteLine ("f"); + f_count++; + return false; + } + + static bool t () + { + Console.WriteLine ("t"); + t_count++; + return true; + } + + static int Main () + { + if (t () && t ()){ + f_count--; + } + + if (t_count != 2) + return 1; + + if (f_count != -1) + return 3; + + f_count = 0; + + if (t () && f ()) + if (t_count != 3 && f_count == 1) + return 2; + + if (f () && f ()) + return 3; + + if (f_count != 2) + return 4; + + if (f () && t ()) + return 5; + + if (f_count != 3) + return 6; + + if (t_count != 3) + return 7; + + // + // reset + // + Console.WriteLine ("or"); + + t_count = f_count = 0; + + if (t () || t ()){ + if (t_count != 1) + return 8; + } else + return 9; + + if (t () || f ()){ + if (f_count != 0) + return 10; + if (t_count != 2) + return 16; + } else + return 11; + + if (f () || f ()){ + return 12; + } else + if (f_count != 2) + return 13; + + if (f () || t ()){ + if (f_count != 3) + return 15; + if (t_count != 3) + return 17; + } else + return 14; + + return 0; + } +} |