serde-deprecated/syntex

syntex successfully parses mismatched brackets

Closed this issue · 1 comments

syntex converts

impl Deserialize for Operation {
    fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
        where D: Deserializer {
        let v = try!(Value::deserialize(deserializer));
        if let Value::Object(ref map) = v.clone() {
            if let Some(&Value::String(ref s) = map.get("type") {
                let result = match s.as_ref() {
                    "constructor" => Deserialize::deserialize(&mut value::Deserializer::new(v)).map(Operation::Constructor),
                    "function" => Deserialize::deserialize(&mut value::Deserializer::new(v)).map(Operation::Function),
                    "event" => Deserialize::deserialize(&mut value::Deserializer::new(v)).map(Operation::Event),
                    _ => Err(SerdeError::custom("Invalid operation type.")),
                };

                return result.map_err(|e| D::Error::custom(format!("{:?}", e).as_ref()));
            }
        }
        Err(D::Error::custom("Invalid operation"))
    }
}

to

    impl Deserialize for Operation {
        fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
         where D: Deserializer {
            let v = try!(Value :: deserialize ( deserializer ));
            if let Value::Object(ref map) = v.clone() { }
            Err(D::Error::custom("Invalid operation"))
        }
    }

Instead syntex should fail to parse the original function, instead of just dropping the erroneous expression.

The following statement will disappear without error in syntex:

if let Some(&Value::String(ref s) = map.get("type") {}