32-bit and 64-bit different type for dynamic array length?

I have a DUnitX test suite that works fine on Win32. But when I try to compile it for Win64, this line generates a compilation error:

Assert.AreEqual(4, Length(r.Values));

[dcc64 Error] ...: E2532 Failed to derive a generic type argument from different argument types for the 'AreEqual' method

r.Values ​​is defined as:

Type TIntegers = TArray<Integer>

Assert.AreEqual has different overloaded implementations, and dcc64 cannot choose the right one ... ok, but why? And why can dcc32 compile this without a problem?

The only key I have is that if I hover over it, Delphi will tell me that Length is of type System.Smallint. There is no implementation of Assert.AreEqual with Smallint parameters ... and, of course, if I pass it Integer, dcc64 will compile it.

But that really bothers me. If I look into the System.pas block, I see that DynArraySetLength accepts the NativeInt parameter ... a 64-bit integer (I would expect an unsigned one, but not sure about that). So why should Length return a signed 16-bit integer? It would seem that trouble awaits, right?

What am I missing?

+4
source share
1 answer

In a 64-bit state, TArray has a type length Int64. As far as I'm concerned, there is an overload AreEqualfor Int64, so he tries to use the generic version: AreEqual<>. But it looks like from the parameters he cannot decide which one.

So, in Win64, do:

 Assert.AreEqual<Int64>(4, Length(r.Values));

or

 Assert.AreEqual(4, Integer(Length(r.Values)));

, , , Win32 Win64, .


FWIW, Length a Smallint. , , " ", Length, () . IDE, .

:

, @RemyLebeau, NativeInt. Win32, Win64, NativeInt - Int32 Win32 Int64 Win64, _DynArrayLength:

Assert.AreEqual<NativeInt>(4, Length(r.Values));
+9

Source: https://habr.com/ru/post/1682829/


All Articles