Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SA1121: Inconsistent behaviour with respect to global using aliases #3594

Open
BBreiden opened this issue Jan 10, 2023 · 3 comments · May be fixed by #3678
Open

SA1121: Inconsistent behaviour with respect to global using aliases #3594

BBreiden opened this issue Jan 10, 2023 · 3 comments · May be fixed by #3678

Comments

@BBreiden
Copy link

If a global using alias is defined in another file, SA1121 does not produce a warning.
For example, the analyzer will not produce a warning in NoWarning.cs, but in AWarning.cs it does:

GlobalUsings.cs:

global using fp64 = System.Double;

NoWarning.cs:

public class TestWarning
{
    private double Method()
    {
        fp64 x = System.Math.PI;
        return x;
    }
}

AWarning.cs:

using MyMath = System.Math;

public class TestWarning2
{
    private double Method()
    {
        fp64 x = MyMath.PI;
        return x;
    }
}
@bjornhellander
Copy link
Contributor

SA1121 takes a shortcut when it doesn't detect any using alias statements in the file, so I assume that it doesn't detect global using aliases from other files.

@bjornhellander
Copy link
Contributor

I haven't been able to find a way to fix this in the current implementation, short of turning off the optimization that I mentioned before. I posted a question to the Roslyn team (dotnet/roslyn#66517) to see if they see a way forward.

@bjornhellander
Copy link
Contributor

bjornhellander commented Jan 22, 2023

This is also related to #2975 (comment) where @sharwell has suggested to rewrite SA1121 as an operation analyzer to improve performance. This problem might go away if that is implemented.

bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Jun 19, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Jun 19, 2023
…ntax tree, by filling the dictionary directly when it is created. In the previous commit, it was checked for global using aliases once and then again for normal using aliases.

DotNetAnalyzers#3594
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Jun 19, 2023
…ntax tree, by filling the dictionary directly when it is created. In the previous commit, it was checked for global using aliases once and then again for normal using aliases.

DotNetAnalyzers#3594
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 17, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Dec 20, 2023
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Jan 3, 2024
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Jan 3, 2024
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Jan 3, 2024
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Mar 23, 2024
bjornhellander added a commit to bjornhellander/StyleCopAnalyzers that referenced this issue Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment