[PATCH] D101702: [clang-format] Add more support for C# 8 nullables

Eliza via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 3 12:09:05 PDT 2021


exv updated this revision to Diff 342497.
exv added a comment.

Remove special whitespace handling for ??=


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101702

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


Index: clang/unittests/Format/FormatTestCSharp.cpp
===================================================================
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -359,8 +359,16 @@
 }
 
 TEST_F(FormatTestCSharp, CSharpNullCoalescingAssignment) {
-  verifyFormat("test \?\?= ABC;");
-  verifyFormat("test \?\?= true;");
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  Style.SpaceBeforeAssignmentOperators = true;
+
+  verifyFormat("test \?\?= ABC;", Style);
+  verifyFormat("test \?\?= true;", Style);
+
+  Style.SpaceBeforeAssignmentOperators = false;
+
+  verifyFormat("test\?\?= ABC;", Style);
+  verifyFormat("test\?\?= true;", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullForgiving) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3191,11 +3191,6 @@
     if (Left.is(TT_CSharpNullCoalescing) || Right.is(TT_CSharpNullCoalescing))
       return true;
 
-    // Space before and after '??='.
-    if (Left.is(TT_CSharpNullCoalescingAssignment) ||
-        Right.is(TT_CSharpNullCoalescingAssignment))
-      return true;
-
     // No space before null forgiving '!'.
     if (Right.is(TT_JsNonNullAssertion))
       return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101702.342497.patch
Type: text/x-patch
Size: 1358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210503/b4017478/attachment.bin>


More information about the cfe-commits mailing list