question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SA1000 ignores 'default' in a default literal expression

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bjornhellandercommented, Jun 24, 2023

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.

1reaction
sharwellcommented, Oct 19, 2021

@jethas-bennettjones you’re seeing #3214

Read more comments on GitHub >

github_iconTop Results From Across the Web

SA1000 doesn't handle 'target-typed' new · Issue #3214
With C# 9.0, SA1000 complains about "target type new expressions": ... SA1000 ignores 'default' in a default literal expression #2420.
Read more >
Default literal expressions in C# 7.1
Default literal expressions let us use default values for types. I think most of my readers know default keyword from C#. Here are...
Read more >
In c#, is it a good practice to return default literal? [closed]
Recently, I saw some are writing code to return default literal for nullable primitive type, is there a real benefit for it?
Read more >
C# 7.0 and 7.1 support in ReSharper - Default literal
Visual Studio 2017 15.3 introduced another nice C# 7.1 feature: the default literal. It can be used instead of the default(T) expression, ...
Read more >
IDE0034: Simplify 'default' expression - .NET
This style rule concerns using the default literal for default value expressions when the compiler can infer the type of the expression.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found