Ambiguous declarations erroneously found for `string` and `array of Char` parameter types
Prerequisites
- [X] This bug is in SonarDelphi, not SonarQube or my Delphi code.
- [X] This bug has not already been reported.
SonarDelphi version
1.6.0
SonarQube version
No response
Issue description
sonar-delphi fails to resolve the correct overload when a single-character string is passed to a function with overloads for both string and array of Char as the relevant parameter.
I noticed this because a warning is logged when scanning JclStrings, and I reduced it to the minimal reproducible example.
Steps to reproduce
procedure Foo(Value: array of Char); overload; begin end;
procedure Foo(Value: string); overload; begin end;
begin
Foo('a'); // [WARN] Ambiguous declarations could not be resolved
Foo('aa'); // no warning logged
end.
Minimal Delphi code exhibiting the issue
No response
I should note that the 'a' value isn't even compatible with the array of Char overload.
It seems to be related specifically to the open array parameter; if you replace array of Char with a type equivalent to array[0..1] of Char then sonar-delphi doesn't warn about the ambiguity (and the 'a' literal is compatible with both, but prefers the string overload).
Constant values (like text literals) cannot be used as arguments to open array parameters.
The compiler error is:
E2192 Constants cannot be used as open array arguments
SonarDelphi isn't currently emulating this restriction correctly. This would be very easy to fix if it was limited to literals (and we might hack an incomplete fix targeting literals), but it applies to all constant expressions. The correct fix is blocked by #116.