CodeMod: dynamic-init-list-ctor
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 19 Oct 2016 00:26:55 +0000 (17:26 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Wed, 19 Oct 2016 00:38:30 +0000 (17:38 -0700)
Summary:
CodeMod: `dynamic-init-list-ctor`.

The `folly::dynamic::dynamic(std::initializer_list<folly::dynamic>)` constructor is deprecated because its meaning is ambiguous and variable across compilers and compiler versions.

This diff codemods uses of that constructor to use `folly::dynamic::array<...>(...)` instead.

This codemod may not get 100%, but that's okay. Any amount helps.

Reviewed By: ot

Differential Revision: D4013979

fbshipit-source-id: c6873dbc8027b38e71a0f291466ed2d9bd204a53

folly/experimental/bser/test/BserTest.cpp
folly/gen/test/BaseTest.cpp

index 8534d5368afd4431dd9faea1f2e524333c00b0a0..e1ee70a32c6a31bdea3930255e386e7c837d45be 100644 (file)
@@ -34,7 +34,7 @@ static const dynamic roundtrips[] = {
     nullptr,
     1.5,
     "hello",
-    {1, 2, 3},
+    folly::dynamic::array(1, 2, 3),
     dynamic::object("key", "value")("otherkey", "otherval"),
 };
 
@@ -47,11 +47,10 @@ const uint8_t template_blob[] =
     "\x1e\x0c\x03\x19";
 
 // and here's what it represents
-static const dynamic template_dynamic = {
+static const dynamic template_dynamic = folly::dynamic::array(
     dynamic::object("name", "fred")("age", 20),
     dynamic::object("name", "pete")("age", 30),
-    dynamic::object("name", nullptr)("age", 25),
-};
+    dynamic::object("name", nullptr)("age", 25));
 
 TEST(Bser, RoundTrip) {
   dynamic decoded(nullptr);
@@ -86,8 +85,8 @@ TEST(Bser, Template) {
 
   // Now check that we can generate this same data representation
   folly::bser::serialization_opts opts;
-  folly::bser::serialization_opts::TemplateMap templates = {
-      std::make_pair(&decoded, folly::dynamic{"name", "age"})};
+  folly::bser::serialization_opts::TemplateMap templates = {std::make_pair(
+      &decoded, folly::dynamic(folly::dynamic::array("name", "age")))};
   opts.templates = templates;
 
   str = folly::bser::toBser(decoded, opts);
index f779c4acb479e54c9d5cc483d07dedf23b5bd897..49c5c5cf5d96a7f2c903889b82f4c62833aa3aec 100644 (file)
@@ -1002,9 +1002,13 @@ TEST(Gen, CopyCount) {
 TEST(Gen, Dynamic) {
   dynamic array1 = dynamic::array(1, 2);
   EXPECT_EQ(dynamic(3), from(array1) | sum);
-  dynamic array2 = {{1}, {1, 2}};
+  dynamic array2 = folly::dynamic::array(
+      folly::dynamic::array(1), folly::dynamic::array(1, 2));
   EXPECT_EQ(dynamic(4), from(array2) | rconcat | sum);
-  dynamic array3 = {{{1}}, {{1}, {1, 2}}};
+  dynamic array3 = folly::dynamic::array(
+      folly::dynamic::array(folly::dynamic::array(1)),
+      folly::dynamic::array(
+          folly::dynamic::array(1), folly::dynamic::array(1, 2)));
   EXPECT_EQ(dynamic(5), from(array3) | rconcat | rconcat | sum);
 }