Skip to content

Commit db14067

Browse files
cjlongoriafacebook-github-bot
authored andcommitted
example broken logic
Summary: ~~This implementation is broken. The test unintentionally uses the "all fields optional" branch. By adding another field to the struct that isn't optional, the "deprecated_optional_with_default_is_some" option doesn't work as expected.~~ ~~I originally thought the test was only passing due to a [special conditional branch in our thrift derserialization that applies when all the fields of a struct are optional](https://www.internalfb.com/code/fbsource/[026629593ef48013189d2a74e0cb9af0baa29e86]/xplat/thrift/compiler/generate/templates/rust/lib/structimpl.mustache?lines=153-159). Now, I think the test is just wrong. I think the test struct should be instantiated with "IAMOPTWITHDEF" as the value. Then test to ensure any null or missing values get derserialized to "IAMOPTWITHDEF"~~ Back to the original idea, this test needs to be updated. Reviewed By: diliop Differential Revision: D76012935 fbshipit-source-id: 9872f9a4391006d07aeca387891ecb8e550f6dee
1 parent 01b2ca1 commit db14067

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

third-party/thrift/src/thrift/lib/rust/src/dep_tests/simplejson.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,14 @@ fn test_deprecated_null_stuff_deser() -> Result<()> {
312312

313313
let sub = test_deprecated_optional_with_default_is_some_if::Struct {
314314
optDef: None,
315+
marker: true,
315316
..Default::default()
316317
};
317318

318-
let inputs = &["{}", r#"{ "optDef": null}"#];
319+
let inputs = &[
320+
r#"{ "marker": true }"#,
321+
r#"{ "optDef": null, "marker": true }"#,
322+
];
319323
for input in inputs {
320324
// Make sure everything is skipped properly
321325
let res = deserialize(*input);

third-party/thrift/src/thrift/lib/rust/src/dep_tests/test_deprecated_optional_with_default_is_some.thrift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace cpp2 facebook
1919
struct Struct {
2020
// @lint-ignore THRIFTCHECKS
2121
1: optional string optDef = "IAMOPTWITHDEF";
22+
2: bool marker;
2223
}
2324

2425
const Struct DEFAULT_STRUCT = {};

0 commit comments

Comments
 (0)