Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# short ternary operator missing space before colon or question mark #58067

Closed
3geek14 opened this issue Sep 29, 2022 · 3 comments
Closed

C# short ternary operator missing space before colon or question mark #58067

3geek14 opened this issue Sep 29, 2022 · 3 comments
Assignees

Comments

@3geek14
Copy link

3geek14 commented Sep 29, 2022

I have a file mwe.cs:

var x=cond?"A":"B";
var y=(cond?"A":"B");
Func(cond?"A":"B");
(cond?"A":"B");
cond?"A":"B";

When I run clang-format --style=LLVM mwe.cs, I get the output:

var x = cond ? "A" : "B";
var y = (cond ? "A" : "B");
Func(cond? "A": "B");
(cond? "A": "B");
cond? "A" : "B";

In the variable assignments, the formatting is correct. In the function call, both spaces are missing, and the same in the following line with parentheses around the ternary expression. In the final line, only the space before the question mark is missing.

As is expected, adding spaces to the input file before the ?s and :s does not change the output.

I have clang-format version 15.0.1 installed.

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 29, 2022

@llvm/issue-subscribers-clang-format

@mydeveloperday
Copy link
Contributor

Its seeing the ? as a CSharpNullable

AnnotatedTokens(L=0, P=0, T=5, C=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=l_paren L=1 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=identifier L=5 PPK=2 FakeLParens= FakeRParens=0 II=0x27611d1a918 Text='cond'
 M=0 C=0 T=CSharpNullable S=0 F=0 B=0 BK=0 P=43 Name=question L=6 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='?'
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=43 Name=string_literal L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='"A"'
 M=0 C=0 T=CSharpNamedArgumentColon S=0 F=0 B=0 BK=0 P=43 Name=colon L=11 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=':'
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=43 Name=string_literal L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='"B"'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=17 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'

@mydeveloperday
Copy link
Contributor

@mydeveloperday mydeveloperday self-assigned this Apr 16, 2023
@mydeveloperday mydeveloperday added the awaiting-review Has pending Phabricator review label Apr 16, 2023
@github-actions github-actions bot removed the awaiting-review Has pending Phabricator review label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants