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.

csharp_prefer_simple_default_expression has faulty heuristic

See original GitHub issue

Version Used:

VS Enterprise 2017 15.3.4

Steps to Reproduce:

  1. Add csharp_prefer_simple_default_expression to your .editorconfig with a value of true:error
  2. 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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jcouvcommented, Dec 26, 2017

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

0reactions
CyrusNajmabadicommented, Nov 14, 2017

15.5p3:

Available when valid:

image

But not when invalid:

image

Read more comments on GitHub >

github_iconTop 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 >

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