Skip to content

Round-trip failure: ser -> de transforms Float(1.0) into Integer(1) #337

@saethlin

Description

@saethlin

This example program probably ought to exit successfully

fn main() {
    let input = "1.0";
    let v: ron::Value = ron::from_str(input).unwrap();
    println!("{:?}", v);
    let ser = ron::to_string(&v).unwrap();
    println!("{:?}", ser);
    let roundtrip = ron::from_str(&ser).unwrap();
    println!("{:?}", roundtrip);
    assert_eq!(v, roundtrip);
}

But it doesn't:

Number(Float(Float(1.0)))
"1"
Number(Integer(1))
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Number(Float(Float(1.0)))`,
 right: `Number(Integer(1))`', src/main.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This seems plausible as a ser/de behavior if RON only has a number type, but if that's the case ron::Value::Number should depend only on the numeric value not the discriminant.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions