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

GCop628 false alarm #300

Open
sungam3r opened this issue Apr 5, 2019 · 4 comments
Open

GCop628 false alarm #300

sungam3r opened this issue Apr 5, 2019 · 4 comments

Comments

@sungam3r
Copy link
Contributor

sungam3r commented Apr 5, 2019

public Task DoSome(int? value) // GCop628: Maybe define this method on 'Nullable' class as it's using 1 of its members (compared to 0 from this type)
{
    if (value.HasValue)
      return Task.CompletedTask;
    return null;
}

Obviously, we cannot move the method inside System.Nullable<T>. The rule should take into account the system types. Also note if you make the method static, then there is no warning.

@Foroughi
Copy link
Contributor

@sungam3r Hi. Its weird b.c I'm not getting the same warning message on the same code. Here is the warning I'm getting :

GCop628: Maybe define this method on 'DoSome' class as it's using 1 of its members (compared to 0 from this type)

Would you please provide the entire class your working on?

@sungam3r
Copy link
Contributor Author

    <PackageReference Include="GCop.All.Common" Version="2.6.0" PrivateAssets="all" />
using System.Threading.Tasks;

namespace Test
{
    internal class Class1
    {
        public Task DoSome(int? value) // GCop628: Maybe define this method on 'Nullable' class as it's using 1 of its members (compared to 0 from this type)
        {
            if (value.HasValue)
                return Task.CompletedTask;
            return null;
        }
    }
}

image

@Foroughi
Copy link
Contributor

Even with using the exact version, I couldn't find this issue. Not in unit tests, not in a real scenario.

Real scenario sample :
Screenshot (5)

Unit test result :

Screenshot (6)

@marjanjavid @Karvan Would you please you guys have a look if you can find the issue on this one ?
@sungam3r Would you please share a light version of your repo?

@sungam3r
Copy link
Contributor Author

sungam3r commented May 1, 2019

ConsoleApp7.zip
изображение
изображение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants