Skip to content

Type inference of floating point numbers through a comparison depends on the order of the operands  #21634

Closed
@shepmaster

Description

@shepmaster

This fails:

fn main() {
    if let Some(value) = "hi".parse() {
        if value <= 0.0 { println!("1") } else { println!("2") };
    }
}

with the error:

error: the type of this value must be known in this context
         if value <= 0.0 { println!("1") } else { println!("2") };
            ^~~~~

Simply flipping the order of the comparison operands allows it to compile:

fn main() {
    if let Some(value) = "hi".parse() {
        if 0.0 >= value { println!("1") } else { println!("2") };
    }
}

Tested with rustc 1.0.0-dev (102ab57d8 2015-01-25 13:33:18 +0000) Originally from this Stack Overflow question

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions