Repository navigation
Conversation
|
Hmm I'm a bit worried about that overflow situation. It feels like one of the main use cases for nint would be pointer arithmetic, and if you try to find the distance between two nint pointers it will throw now. The converter currently does use Option Strict Off for its output. |
Roslyn displays System.IntPtr/UIntPtr with the nint/nuint keywords (the same types since C# 11), so name expansion wrote them as the nonexistent System.nint/System.nuint (in declarations, generic arguments and member access such as nint.MaxValue) and added casts like `(nint)hWnd` for plain IntPtr arguments. VB has no such names (BC30002), and the failed binding also stopped the reducer from undoing the rest of the expansion. The expander now puts the keyword back, and a name bound to a native integer type is converted to the VB name of its type. A user type named nint and explicit IntPtr/UIntPtr are unchanged.
VB sees only IntPtr/UIntPtr's own operators (+ and - with an Integer offset, =, <>) and explicit conversions; .NET 7's numeric operators are explicit interface implementations. So with Option Strict Off `end - start` on two nint values narrowed `start` to Integer and threw beyond Int32, and comparisons, *, /, Mod, bitwise operators, shifts and unary - / Not didn't compile. A built-in C# operator on nint/nuint is now evaluated on Long/ULong, with the result converted back when C#'s result is a native integer; division becomes \. Compound assignments are expanded the same way. Where VB's own operator does what C#'s does (=, <>, and + or - with an Integer offset), the output is unchanged.
924e0eb to
430ce0f
Compare
|
Good catch, thanks. I've added the casts in a separate commit (430ce0f). VB only sees IntPtr/UIntPtr's own operators ( A built-in operator on nint/nuint is now evaluated on Long/ULong and converted back when C#'s result is a native integer, e.g. Tests: a CS -> VB self-verifying test ( Still not handled, and noted in the class doc: like other integer arithmetic, the Long/ULong operation is overflow-checked in VB, where C# is unchecked by default. Also not handled: |
Problem
Roslyn displays
IntPtr/UIntPtrasnint/nuint, so name expansion wrote the nonexistentSystem.nint/System.nuint(declarations, generic arguments,nint.MaxValue) and casts likeCType(hWnd, nint)for plainIntPtrarguments, which also stopped the rest of the expansion from being reduced. All give BC30002 in VB.Solution
IntPtr/UIntPtr.nintandnuint, native integer arithmetic, and implicit conversions to native ints, which are narrowing in VB (nint local = 5;->Dim local As IntPtr = 5compiles only with Option Strict Off).IntPtrargument to an extern method, and a user type namednintand explicitIntPtrstaying unchanged)Process