-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Description
Championed issue: dotnet/csharplang#6065
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/numeric-intptr.md
Compiler
- Public API:
-
IsNativeIntegerType -
CreateNativeIntegerTypeSymbol()
-
- Built-in conversions are standard implicit and explicit (see PR Treat some nint/nuint conversions as standard conversions #61034)
- Add
TargetFramework.Net70and use that for our tests (issue Add TargetFramework.Net70 #61463) - spec (PR)
- Tied to runtime feature flag
- Not tied to
-langversion - No
[NativeInteger]attributes emitted - Members defined on IntPtr/UIntPtr are available from IntPtr/UIntPtr and nint/nuint:
- interfaces
- static members
- instance members
- constructors
- implicit and explicit conversion operators
- overridden implementations: ToString(), GetHashCode(), Equals()
- Equivalence between nint/IntPtr and nuint/UIntPtr for:
- interface implementations
- overloads
- partial methods
- generic type constraints
- type inference
- type unification
- Retargeting when a compilation reference that uses wrapped nint is referenced in a compilation that uses .NET 7 (see
RetargetingFromNonNumericToNumericIntPtrCorlibandRetargetingFromNumericIntPtrToNonNumericCorlib) - Built-in operators for nint/nuint apply to IntPtr/UIntPtr (and IntPtr?/UIntPtr?)
- built-in conversions
- built-in unary and binary operators
- Constants (in int/uint range) supported for IntPtr/UIntPtr:
-
constallowed - constant folding
- parameter default values
-
switchvalue
-
- fix better conversion rules (issue) and update specs accordingly
- Verify with
>>>(seeUnsignedRightShift) - Breaking changes:
- for
checkedoperator+ and operator- with IntPtr/UIntPtr - breaking changes documented
- for
- Other scenarios called out by [Proposal]: First class native integer support csharplang#4385
BCL
- Add runtime feature flag (tracked by [API Proposal]: Add RuntimeFeature field to identify support for numeric IntPtr type runtime#67966, done in Expose the
RuntimeFeature.NumericIntPtrmember for C# 11 runtime#69322) - Modify
System.IntPtrandSystem.UIntPtr(needs to include>>>) (not applicable)
Productivity
- QuickInfo (validated manually in PR Unify nint and IntPtr #60913, but can't be unittested because IDE tests run on .NET 6 BCL)
- Classification (
SemanticClassifierTests.NativeInteger) - MetadataAsSource (
MetadataAsSource.MetadataAsSourceTests+CSharp.TestNativeInteger) - Prefer keyword over full type name (
UseExplicitTypeTests.InNativeIntIntrinsicType, this should follow the preference for built-in types) - Simplify type name
-
using x = System.IntPtr;should not simplify tonint
-
- Update simplification defaults to suggest updating
IntPtrtonintif that option is set- In cref:
<see cref="nint"/>,<see cref="System.IntPtr"/>(completion issue, should offer to simplify tonint)
- In cref:
- Simplify
nint x = default(nint);to eithernint x = default;ornint x = 0;
Relates to test plan for native ints: #38821
Relates to statics in interfaces and numerics design: https://github.com/dotnet/designs/blob/main/accepted/2021/statics-in-interfaces/README.md
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Language/design