sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

Widen real types to `Extended` when inferring the type of an inline var

Open Cirras opened this issue 1 year ago • 0 comments

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

Cirras avatar Dec 05 '23 23:12 Cirras