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.

SA1137/SA1316 false positive when using primary constructors

See original GitHub issue

Problem

The following code block causes false warnings. (LangVersion set to preview)

class A(int b)
{
    public int B => b;
}

image image

How this is a problem

It is suggesting to format the code like so:

class A(int B)
{
public int B => b;
}

When using primary constructors in non-record types, they’re considered parameters/fields, and therefore use camelCase.

The lack of indentation is clearly unintended since the same thing isn’t raised for record types, and it goes against the rule of contents in blocks having indentation in the first place.

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Emik03commented, Jun 25, 2023

Just wanted to chime in one last time to mention that this indeed has been fixed as of version 2023.2 EAP 5 with the latest toolchain preview.

image

0reactions
Emik03commented, May 28, 2023

Interesting, this only happens inside Rider.

image

This is weird, because in theory it shouldn’t have a problem since I use the newest toolchain, but I suppose it is because Rider runs on .NET Core v7.0.4 (see detailed information above)

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

False positive S1172 for constructor parameter
A false-positive is when an issue is raised unexpectedly on code that should not trigger an issue, or where the suggested action doesn't...
Read more >
S3604 misunderstands primary constructors in C# - ...
Sonarlint wants to move the two member initializers = end - start + 1 and = start . This is obviously incorrect, and...
Read more >
Preview Feedback: C# 12 Primary constructors #7109
Primary constructors don't create fields. They are parameters which can be captured if used beyond the lifecycle of the constructor. The method ...
Read more >
C#12 class and struct Primary Constructors : r/dotnet
Personally I'm a little bummed out because my goal for a representative constructor like this is to remove the tedium of writing property ......
Read more >
"Constructor 'x' is never used" false positive when ...
CPP-18806 Subclass constructor is shown as unused while it is actually used by factory method using list initialization ; CPP-19433 "Constructor is never...
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