sonar-delphi
sonar-delphi copied to clipboard
Widen real types to `Extended` when inferring the type of an inline var
Prerequisites
- [X] This improvement has not already been suggested.
- [X] This improvement would be generally useful, not specific to my code or setup.
Engine area
Delphi language support
Improvement description
In the below example, Bar
is inferred as Extended
despite the assigned value having an explicitly-known type of Double
.
var
Foo: Double;
begin
var Bar := Foo;
end;
Our type inference rules don't currently reflect this behavior.
Rationale
Match the behavior of the compiler, even when it's weird.
See: https://quality.embarcadero.com/browse/RSP-42107