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

IDE0049 should be updated to suggest converting IntPtr to nint and UIntPtr to nuint. #63421

Closed
buyaa-n opened this issue Aug 16, 2022 · 5 comments · Fixed by #66742
Closed

IDE0049 should be updated to suggest converting IntPtr to nint and UIntPtr to nuint. #63421

buyaa-n opened this issue Aug 16, 2022 · 5 comments · Fixed by #66742
Labels
Area-IDE Feature - IDE0049 Prefer builtin type Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@buyaa-n
Copy link
Contributor

buyaa-n commented Aug 16, 2022

Brief description:

As mentioned in dotnet/runtime#72348 with the numeric IntPtr feature, nint is now an alias for System.IntPtr and nuint is alias for System.UIntPtr, the analyzer IDE0049 should be updated to suggest converting IntPtr to nint and UIntPtr to nuint. Preferably default to "Info" level.

Languages applicable:

C# only

Additional information:

Related to dotnet/runtime#72348

Documentation requirements:

When this analyzer is updated, the Documentation for IDE0049 analyzers could be updated accordingly.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Aug 16, 2022
@CyrusNajmabadi
Copy link
Member

@cston can you point to docs (or give the rules) on precisely when we should consider these types equivalent?

@cston
Copy link
Member

cston commented Aug 16, 2022

The compiler treats nint / nuint as aliases for System.IntPtr / System.UIntPtr when compiling with a corlib that includes System.Runtime.CompilerServices.RuntimeFeature.NumericIntPtr. Otherwise, the pairs of types are considered distinct.

@CyrusNajmabadi
Copy link
Member

Sounds good. I see tehre is AssemblySYmbol.RuntimeSupportsNumericIntPtr. Could we expose that publicly?

@ryzngard ryzngard added this to the Backlog milestone Aug 22, 2022
@ryzngard ryzngard added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 22, 2022
@buyaa-n
Copy link
Contributor Author

buyaa-n commented Aug 23, 2022

This also should consider @jkotas suggestion in the original issue:

It would be nice for the code-fixer to suggest replacing IntPtr with actual pointer types where the code is actually operating on pointers.

Blank replacing IntPtr with nint will often make code harder to understand. See discussion in dotnet/runtime#70297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature - IDE0049 Prefer builtin type Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants