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