This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Recognize C# nullable types
ClosedPublic

Authored by jbcoe on Feb 27 2020, 8:07 AM.

Details

Summary

Do not confuse C# nullable types with conditional expressions.

Do not put a space before the ? in [access-modifier] Type? variableName;

Diff Detail

Event Timeline

jbcoe created this revision.Feb 27 2020, 8:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 27 2020, 8:07 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jbcoe marked an inline comment as done.Feb 27 2020, 8:57 AM
jbcoe added inline comments.
clang/unittests/Format/FormatTestCSharp.cpp
178

This will be formatted as

public Person(string firstName, string lastName, int age = null);

without the Nullable Type.

krasimir accepted this revision.Feb 27 2020, 11:32 AM
krasimir added inline comments.
clang/unittests/Format/FormatTestCSharp.cpp
609

Could you also try/add a test for an array of nullable type (from language ref docs here) (also an example of using new with a nullable type):

// An array of a nullable type:
int?[] arr = new int?[10];
This revision is now accepted and ready to land.Feb 27 2020, 11:32 AM
MyDeveloperDay accepted this revision.Feb 28 2020, 12:48 AM
jbcoe updated this revision to Diff 247193.Feb 28 2020, 2:24 AM

Add additional test following review discussion

This revision was automatically updated to reflect the committed changes.