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

SA1000 ignores 'default' in a default literal expression #2420

Open
sharwell opened this issue Jun 16, 2017 · 5 comments · May be fixed by #3838
Open

SA1000 ignores 'default' in a default literal expression #2420

sharwell opened this issue Jun 16, 2017 · 5 comments · May be fixed by #3838
Assignees

Comments

@sharwell
Copy link
Member

sharwell commented Jun 16, 2017

Currently SA1000 is getting reported for the following C# 7.1 syntax:

var x = value == null ? default : 3;

Edit: a workaround is now implemented to simply ignore default literal expressions. The bug has a new title for providing full support for this keyword.

@sharwell sharwell self-assigned this Jun 16, 2017
sharwell added a commit to sharwell/StyleCopAnalyzers that referenced this issue Jun 16, 2017
Full support for C# 7.1 will be added when it is finally released, but this
change offers a clean workaround for DotNetAnalyzers#2420 in the interim.
@sharwell sharwell changed the title SA1000 incorrectly reported for default expressions SA1000 ignores 'default' in a default literal expression Jun 10, 2018
@tillig
Copy link

tillig commented Mar 3, 2021

Under .NET Core 3.1 and StyleCopAnalyzers 1.1.118 this appears to have been resolved (probably due to the submitted PR) and can be closed.

@sharwell
Copy link
Member Author

sharwell commented Mar 4, 2021

It's still open to review cases where diagnostics should be reported. Right now diagnostics are not reported even for unexpected spacing, such as when the spaces around default are removed.

@jethas-bennettjones
Copy link

I'm using .NET 5 and v1.1.118 of the analyzer, and I'm seeing it.
image

@sharwell
Copy link
Member Author

@jethas-bennettjones you're seeing #3214

@bjornhellander
Copy link
Contributor

I think the current behaviour is correct. In this context, default is equivalent to a literal or a variable, so I expect SA1000 to continue to ignore it. Removing the trailing space in this example already triggers SA1003 and SA1024.

SA1000 tests should be added, though, to make sure that it doesn't regress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants