aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestCSharp.cpp
diff options
context:
space:
mode:
authorEliza Velasquez <exv@google.com>2021-05-06 12:06:00 +0200
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2021-05-06 12:11:15 +0200
commitec725b307f3fdc5656459047bab6e69669d9534f (patch)
tree8d93bc2541a6038bc0c9f005e231ff836deefc47 /clang/unittests/Format/FormatTestCSharp.cpp
parenta437befa8f8580b3b4f2226b208a05da078c8b20 (diff)
downloadllvm-ec725b307f3fdc5656459047bab6e69669d9534f.zip
llvm-ec725b307f3fdc5656459047bab6e69669d9534f.tar.gz
llvm-ec725b307f3fdc5656459047bab6e69669d9534f.tar.bz2
[clang-format] Fix C# nullable-related errors
This fixes two errors: Previously, clang-format was splitting up type identifiers from the nullable ?. This changes this behavior so that the type name sticks with the operator. Additionally, nullable operators attached to return types in interface functions were not parsed correctly. Digging deeper, it looks like interface bodies were being parsed differently than classes and structs, causing MustBeDeclaration to be incorrect for interface members. They now share the same logic. One other change is reintroducing the CSharpNullable type independent of JsTypeOptionalQuestion. Despite having a similar semantic purpose, their actual syntax differs quite a bit. Reviewed By: MyDeveloperDay, curdeius Differential Revision: https://reviews.llvm.org/D101860
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r--clang/unittests/Format/FormatTestCSharp.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 875ff74..427f725 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -848,6 +848,21 @@ public class A {
verifyFormat(R"(var x = (int?)y;)", Style); // Cast to a nullable type.
verifyFormat(R"(var x = new MyContainer<int?>();)", Style); // Generics.
+
+ verifyFormat(R"(//
+public interface I {
+ int? Function();
+})",
+ Style); // Interface methods.
+
+ Style.ColumnLimit = 10;
+ verifyFormat(R"(//
+public VeryLongType? Function(
+ int arg1,
+ int arg2) {
+ //
+})",
+ Style); // ? sticks with identifier.
}
TEST_F(FormatTestCSharp, CSharpArraySubscripts) {