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