uint accepts negative numbers

75fd9d0
Opened by Gary Kwong [:gkw] at 2010-11-21 18:30:20
fn main() {
    let uint x = -1 as uint;
    log x;
}

This testcase seems to show that negative numbers can be accepted as unsigned integers. Unsigned integers should only comprise of non-negative numbers.

(not sure if this is working as intended.)

On repository revision 5955e23343e606daf0341cb7ea66b8b436868ba6 on Mac 10.6.5.

Output: $ ./rustboot -L . -o 2out.out 2test.rs

$ ./2out.out

rt: --- rt: a5ed:main:main: rust: -1 (0xffffffff)

  1. This is correct behavior. The "as" operator performs a cast. "-1" is an int, and "as uint" casts it to uint. The logging system that displays "-1" and "0xffffffff" simply doesn't know enough to differentiate int and uint, so it displays both. Limitation of the logging system.

    Graydon Hoare at 2010-11-21 18:30:20