csharp_prefer_simple_default_expression has faulty heuristic
See original GitHub issueVersion Used:
VS Enterprise 2017 15.3.4
Steps to Reproduce:
- Add
csharp_prefer_simple_default_expression
to your .editorconfig with a value oftrue:error
- Add the statement
object i = default(int)
to your code.
Expected Behavior:
No error should be triggered, since the target type (object
) is more general than the type specified to default
.
Actual Behavior:
An error is triggered, suggesting the statement be simplified to:
object i = default;
Which obviously has different semantics.
This problem is particularly pertinent to the declaration of dependency or bindable properties:
public static readonly BindableProperty SomeProperty = BindableProperty.Create(
nameof(Some),
typeof(Me),
defaultValue: default(int));
This triggers the rule when it should not, since defaultValue
is of type object
.
Here is a repro: EditorConfigRepro.zip
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Psych Ch 7 Flashcards
Faulty heuristic in which you make a decision based on information readily available to you. Thinking, including perception, learning, problem, solving, ...
Read more >Decision-Making - Free Sketchy MCAT Lesson
A potential problem with using the representativeness heuristic is the base rate fallacy, where people rely on their past experiences and beliefs instead...
Read more >Heuristics Definition
Heuristics are part of how the human brain evolved and is wired, allowing individuals to quickly reach reasonable conclusions or solutions to complex...
Read more >Problem Solving – Psychology – H5P Edition
An algorithm is a problem-solving formula that provides you with step-by-step instructions used ... A heuristic is another type of problem solving strategy....
Read more >Judgment under Uncertainty: Heuristics and Biases Amos ...
We suggest that the phenomenon of re- gression remains elusive because it is in- compatible with the belief that the predicted outcome should...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll go ahead and close since it was fixed already. @kentcb Feel free to re-open if you still run into this with 15.5 (or later). Thanks
15.5p3:
Available when valid:
But not when invalid: