-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtimecode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixer
Milestone
Description
With the advert of the numeric IntPtr feature, nint is an alias for System.IntPtr just like int is an alias for System.Int32. We should add analyzers and fixers to make it clear to user code, especially to those who think that IntPtr represents an opaque pointer-sized value. Here's what the analyzers should do:
IDE0049should be updated to suggest convertingIntPtrtonintandUIntPtrtonuint.U?IntPtr.Zero➡0or(nu?int)0if it would introduce ambiguitynew U?IntPtr(x)➡xor(nu?int)xif it would introduce ambiguity, orunchecked((nu?int)x)if we are in acheckedcontext.x.ToU?Int32()➡checked((u?int)x)or(u?int)xif we are in acheckedcontextx.ToU?Int64()➡unchecked((u?long)x)or(u?long)xif we are in anuncheckedcontextx.ToPointer()➡(void*) x- Convert explicit casts between
U?IntPtrandu?intoru?long, tonu?int, while taking the overflow checking context into account (too many to list).
These analyzers and fixers should be triggered only if the underlying runtime supports numeric IntPtr. Some of them might be legal even without it but it's not necessary to make it more complicated.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtimecode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixer