This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] C# short ternary operator misinterpreted as a CSharpNullable
ClosedPublic

Authored by MyDeveloperDay on Apr 16 2023, 10:01 AM.

Details

Summary

Refactor the CSharpNullable assignment code to be a little easier to read (Honestly I don't like it when an if expression get really long and complicated).
Handle the case where '?' is actually a ternary operator.

Fixes: #58067
https://github.com/llvm/llvm-project/issues/58067

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 16 2023, 10:01 AM
MyDeveloperDay requested review of this revision.Apr 16 2023, 10:01 AM

The exclusions are not complete for example cond? foo() : "B"; would still fail. but this moves us a little closer

MyDeveloperDay added a reviewer: exv.EditedApr 16 2023, 10:06 AM

@exv any thoughts on this one? given that you were the author of D101860: [clang-format] Fix C# nullable-related errors and
@jbcoe as you were the author of D75983: [clang-format] Improved identification of C# nullables

HazardyKnusperkeks added inline comments.
clang/lib/Format/TokenAnnotator.cpp
1338–1342

Even if there are more negations, I can read this better.

This revision is now accepted and ready to land.Apr 16 2023, 12:05 PM

simplify negative if

MyDeveloperDay marked an inline comment as done.Apr 17 2023, 11:45 AM
owenpan accepted this revision.Apr 17 2023, 3:48 PM
owenpan added inline comments.
clang/unittests/Format/TokenAnnotatorTest.cpp
1730

Nit: no trailing newlines here and below.

This revision was landed with ongoing or failed builds.Apr 18 2023, 2:19 AM
This revision was automatically updated to reflect the committed changes.