[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 16 08:19:37 PDT 2021


MyDeveloperDay updated this revision to Diff 352444.
MyDeveloperDay added a comment.

I wanted to add some more tests and this really only manifested itself using `lock` and `using`  although the use of them is not generally broken when not using them in a Lambda expression


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104388/new/

https://reviews.llvm.org/D104388

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,76 @@
     };
 })",
                MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+               "{\n"
+               "    Function(Val, (Action)(() => {\n"
+               "                 lock (mylock)\n"
+               "                 {\n"
+               "                     if (true)\n"
+               "                     {\n"
+               "                         A.Remove(item);\n"
+               "                     }\n"
+               "                 }\n"
+               "             }));\n"
+               "}",
+               MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+               "{\n"
+               "    Function(Val, (Action)(() => {\n"
+               "                 using (var a = new Lock())\n"
+               "                 {\n"
+               "                     if (true)\n"
+               "                     {\n"
+               "                         A.Remove(item);\n"
+               "                     }\n"
+               "                 }\n"
+               "             }));\n"
+               "}",
+               MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+               "{\n"
+               "    Function(Val, (Action)(() => {\n"
+               "                 if (true)\n"
+               "                 {\n"
+               "                     A.Remove(item);\n"
+               "                 }\n"
+               "             }));\n"
+               "}",
+               MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+               "{\n"
+               "    Function(Val, (Action)(() => {\n"
+               "                 do\n"
+               "                 {\n"
+               "                     A.Remove(item);\n"
+               "                 } while (true)\n"
+               "             }));\n"
+               "}",
+               MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+               "{\n"
+               "    Function(Val, (Action)(() => { A.Remove(item); }));\n"
+               "}",
+               MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+               "{\n"
+               "    Function(Val, (() => {\n"
+               "                 lock (mylock)\n"
+               "                 {\n"
+               "                     if (true)\n"
+               "                     {\n"
+               "                         A.Remove(item);\n"
+               "                     }\n"
+               "                 }\n"
+               "             }));\n"
+               "}",
+               MicrosoftStyle);
 }
 
 TEST_F(FormatTestCSharp, CSharpObjectInitializers) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1927,6 +1927,12 @@
         parseBracedList();
       }
       break;
+    case tok::equal:
+      if (Style.isCSharp() && FormatTok->is(TT_FatArrow))
+        parseBracedList();
+      else
+        nextToken();
+      break;
     case tok::kw_class:
       if (Style.Language == FormatStyle::LK_JavaScript)
         parseRecord(/*ParseAsExpr=*/true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104388.352444.patch
Type: text/x-patch
Size: 3456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210616/ad52a332/attachment.bin>


More information about the cfe-commits mailing list