[Rtti] Rtti.Invoke cast args to type of params
System Information
- Operating system: Linux
- Processor architecture: x86-64
procedure TTestObj.Test(V: Single);
...
Context.GetType(TTestObj).GetMethod('Test').Invoke(..., [TValue.From<Double>(10.2)])
Now this test may lead to undesirable behavior because the current implementation of Rtti.Invoke passes arguments by reinterpreting memory (in this case taking a pointer to Double and dereferencing it as Single). In more complex cases sigfault is possible (for example, when passing structures).
This patch calls TValue.TryCast in case of argument and parameter types mismatch.
The patch also removes conversions from Enum to Enum and from Integer to Char. But conversions between integer types are added.
All changes are compatible in Delphi, the test can be compiled in Delphi for testing.
Patch and test Patch.patch