2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
2011-06-13 19:25:36 -05:00
|
|
|
// Issue 483 - Assignment expressions result in nil
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2011-06-13 19:25:36 -05:00
|
|
|
fn test_assign() {
|
2015-03-25 19:06:52 -05:00
|
|
|
let mut x: isize;
|
2013-08-17 10:37:42 -05:00
|
|
|
let y: () = x = 10;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 10);
|
2013-08-17 10:37:42 -05:00
|
|
|
assert_eq!(y, ());
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut z = x = 11;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 11);
|
2013-08-17 10:37:42 -05:00
|
|
|
assert_eq!(z, ());
|
2011-06-15 13:19:50 -05:00
|
|
|
z = x = 12;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 12);
|
2013-08-17 10:37:42 -05:00
|
|
|
assert_eq!(z, ());
|
2011-06-13 19:25:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_assign_op() {
|
2015-03-25 19:06:52 -05:00
|
|
|
let mut x: isize = 0;
|
2013-08-17 10:37:42 -05:00
|
|
|
let y: () = x += 10;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 10);
|
2013-08-17 10:37:42 -05:00
|
|
|
assert_eq!(y, ());
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut z = x += 11;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 21);
|
2013-08-17 10:37:42 -05:00
|
|
|
assert_eq!(z, ());
|
2011-06-15 13:19:50 -05:00
|
|
|
z = x += 12;
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(x, 33);
|
2013-08-17 10:37:42 -05:00
|
|
|
assert_eq!(z, ());
|
2011-06-13 19:25:36 -05:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() { test_assign(); test_assign_op(); }
|