Unverified Commit 1155634c authored by Mark Hammond's avatar Mark Hammond Committed by GitHub
Browse files

Method objects now iterate their "throws" type. (#2389)

parent 9c6602cc
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -133,7 +133,8 @@ impl Function {
            self.arguments
                .iter()
                .flat_map(Argument::iter_types)
                .chain(self.return_type.iter().flat_map(Type::iter_types)),
                .chain(self.return_type.iter().flat_map(Type::iter_types))
                .chain(self.throws.iter().flat_map(Type::iter_types)),
        )
    }

@@ -426,4 +427,29 @@ mod test {
            "informative docstring"
        );
    }

    #[test]
    fn test_iter_types() {
        let f = Function {
            name: "fn".to_string(),
            module_path: "fn".to_string(),
            is_async: false,
            arguments: vec![Argument {
                name: "a".to_string(),
                type_: Type::Int32,
                by_ref: false,
                optional: true,
                default: None,
            }],
            return_type: Some(Type::Int64),
            ffi_func: FfiFunction::default(),
            docstring: None,
            throws: Some(Type::Int8),
            checksum_fn_name: "".to_string(),
            checksum: None,
        };
        assert!(f.iter_types().any(|t| matches!(t, Type::Int32)));
        assert!(f.iter_types().any(|t| matches!(t, Type::Int64)));
        assert!(f.iter_types().any(|t| matches!(t, Type::Int8)));
    }
}
+8 −2
Original line number Diff line number Diff line
@@ -463,7 +463,12 @@ impl Constructor {
    }

    pub fn iter_types(&self) -> TypeIterator<'_> {
        Box::new(self.arguments.iter().flat_map(Argument::iter_types))
        Box::new(
            self.arguments
                .iter()
                .flat_map(Argument::iter_types)
                .chain(self.throws.iter().flat_map(Type::iter_types)),
        )
    }
}

@@ -616,7 +621,8 @@ impl Method {
            self.arguments
                .iter()
                .flat_map(Argument::iter_types)
                .chain(self.return_type.iter().flat_map(Type::iter_types)),
                .chain(self.return_type.iter().flat_map(Type::iter_types))
                .chain(self.throws.iter().flat_map(Type::iter_types)),
        )
    }