https://quality.embarcadero.com/browse/RSP-23056
Debugger watch / evaluate shows wrong values for inline declared local variables with duplicate names within same routine.
Put a breakpoint on each of the lines with breakpoint in the comment.
Run
at A, hover over variable s, or evaluate s shows value A
at C, hover over variable s, or evaluate s shows value A - should have been C
The actual value is C - so it is a debugger bug
program ReusedLocalVariables;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
type
TTest = class
public
procedure Check(const aValue: String);
procedure Test;
end;
procedure TTest.Check(const aValue: String);
begin
Writeln(aValue);
end;
procedure TTest.Test;
begin
begin
var s := 'A';
Check(s); // Breakpoint: S shows 'A' - Output in check = 'A'
end;
begin
var s := 'C';
Check(s); // Breakpoint: S shows 'A' - should have been 'C' - Output in check = 'C'
end;
end;
begin
try
var Test := TTest.Create;
try
Test.Test;
Test.Free;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
finally
Write('Press Enter: ');
Readln;
end;
end.