You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SA1206 firing incorrectly for required in C# 11 #3527
SA1206: The 'required' modifier should appear before 'public'
Reacted by Noah Stolk, Muhammad Rehan Saeed, David Ferretti, Tomasz Buchholz, Jan Ivar Carlsen, ldeluigi, Robert Larkins, Domn Werner, laggage, Jeremy Regnerus and 17 more
I also notice that the code fix bails out and does nothing if applied to an unknown modifier. Would be nice if the analyzer did the same, to avoid these endless false positives as the language evolves. Not a big problem with this particular analyzer, but while someone fixes the false positive I think it would be good if the analyzer could be redesigned at the same time.
I tried to create a unit test case, but fail to make the tested code compile: error CS1519: Invalid token 'int' in class, record, struct, or interface member declaration
Could for example be because Microsoft.CodeAnalysis.CSharp.Workspaces 4.3.0-1.final doesn't support this syntax, or maybe we need to configure the tested project to use reference assemblies for .net 7.0?
The latest code analysis package was from a couple of days ago, but I don't know how recent the actual code is. Let´s wait for the next beta and try again.
I have a fix that I am almost happy with (using version 4.3.0-2.final of Roslyn), except that it causes some tests for 1503, 1519 and 1520 to fail due to changed formatting behaviour in the new Roslyn version. I have confirmed that these regressions happen even if I only update that package, so it's not related to the changes for the new modifier.
All failing tests are called TestCodeFixProviderWithAlternateIndentationAsync and they only fail in the c# 11 test project, which is the one with the new Roslyn version. All tests use the SA1503CodeFixProvider to add missing braces using the method SyntaxFactory.Block().
Xunit.Sdk.TrueException: 'Context: Iterative code fix application
content of '/0/Test0.cs' did not match. Diff shown with expected as baseline:
using System.Diagnostics;
public class Foo
{
public void Bar(int i)
{
if (i == 0)
- {
- Debug.Assert(true);
- }
- }
+ {
+ Debug.Assert(true);
+ }
+ }
}
Expected: True
Actual: False'
@Malgefor, there is a pull request prepared, but we are having problems with a bug in the Roslyn version needed to add tests for this change. I have created #3580 to (as a first step) just update the Roslyn version with suggestions on how to temporarily handle the Roslyn bug.
It's a bit complicated. I need to update dotnet/roslyn-sdk so we can update that dependency, but that work has been blocked on updates to microsoft/vs-extension-testing. Hopefully back in a good state soon.
Activity
bjornhellander commentedon Jun 19, 2022
I also notice that the code fix bails out and does nothing if applied to an unknown modifier. Would be nice if the analyzer did the same, to avoid these endless false positives as the language evolves. Not a big problem with this particular analyzer, but while someone fixes the false positive I think it would be good if the analyzer could be redesigned at the same time.
bjornhellander commentedon Jun 19, 2022
I tried to create a unit test case, but fail to make the tested code compile:
error CS1519: Invalid token 'int' in class, record, struct, or interface member declarationCould for example be because Microsoft.CodeAnalysis.CSharp.Workspaces 4.3.0-1.final doesn't support this syntax, or maybe we need to configure the tested project to use reference assemblies for .net 7.0?
stephentoub commentedon Jun 19, 2022
You'll need a really recent build of the C# 11 compiler, e.g. in the last two weeks or so.
bjornhellander commentedon Jun 19, 2022
The latest code analysis package was from a couple of days ago, but I don't know how recent the actual code is. Let´s wait for the next beta and try again.
Update SA1206 to ignore unknown modifiers. Previously triggered for t…
NOT READY Update SA1206 to handle c# 11 modifier "required"
bjornhellander commentedon Jul 17, 2022
I have a fix that I am almost happy with (using version 4.3.0-2.final of Roslyn), except that it causes some tests for 1503, 1519 and 1520 to fail due to changed formatting behaviour in the new Roslyn version. I have confirmed that these regressions happen even if I only update that package, so it's not related to the changes for the new modifier.
All failing tests are called TestCodeFixProviderWithAlternateIndentationAsync and they only fail in the c# 11 test project, which is the one with the new Roslyn version. All tests use the SA1503CodeFixProvider to add missing braces using the method
SyntaxFactory.Block().Do you have any insights on this, @sharwell?
bjornhellander commentedon Jul 29, 2022
On hold until a fix for the formatting is available: dotnet/roslyn#63013
Update SA1206 to ignore unknown modifiers. Previously triggered for t…
NOT READY Update SA1206 to handle c# 11 modifier "required"
Brunni commentedon Nov 21, 2022
Are there any news about the required modifier? I get "indention errors" here.
usausa commentedon Nov 30, 2022
I am also waiting for this issue to be resolved.
Malgefor commentedon Jan 17, 2023
Any update on this issue?
bjornhellander commentedon Jan 30, 2023
@Malgefor, there is a pull request prepared, but we are having problems with a bug in the Roslyn version needed to add tests for this change. I have created #3580 to (as a first step) just update the Roslyn version with suggestions on how to temporarily handle the Roslyn bug.
How do you want to handle this, @sharwell?
sharwell commentedon Jan 30, 2023
It's a bit complicated. I need to update dotnet/roslyn-sdk so we can update that dependency, but that work has been blocked on updates to microsoft/vs-extension-testing. Hopefully back in a good state soon.
Update SA1206 to ignore unknown modifiers. Previously triggered for t…
Update SA1206 to handle c# 11 modifier "required"
Update SA1206 to handle c# 11 modifier "required"
Update SA1206 to handle c# 11 modifier "required"
Update SA1206 to handle c# 11 modifier "required"
tzachihakmon commentedon Feb 24, 2025
Hey im with version 1.2.0-beta.556 and its not working yet, any news?
bjornhellander commentedon Feb 24, 2025
@tzachihakmon As far as I understand, this was fixed in 1.2.0-beta.507. Create a new issue if it's not working.
requiredkeyword #3937 as a duplicate of this issue