Skip to content

Test plan for "numeric IntPtr" #60578

@jcouv

Description

@jcouv

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.Net70 and 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 RetargetingFromNonNumericToNumericIntPtrCorlib and RetargetingFromNumericIntPtrToNonNumericCorlib)
  • 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:
    • const allowed
    • constant folding
    • parameter default values
    • switch value
  • fix better conversion rules (issue) and update specs accordingly
  • Verify with >>> (see UnsignedRightShift)
  • Breaking changes:
    • for checked operator+ and operator- with IntPtr/UIntPtr
    • breaking changes documented
  • Other scenarios called out by [Proposal]: First class native integer support csharplang#4385

BCL

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 to nint
  • Update simplification defaults to suggest updating IntPtr to nint if that option is set
    • In cref: <see cref="nint"/>, <see cref="System.IntPtr"/> (completion issue, should offer to simplify to nint)
  • Simplify nint x = default(nint); to either nint x = default; or nint 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

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Language/design

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions