View Issue Details

IDProjectCategoryView StatusLast Update
0038207FPCCompilerpublic2021-01-01 17:04
ReporterJulian Puhl Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx64OSWindows 
Product Version3.3.1 
Summary0038207: Recent type helper fixes introduce bug with "with" syntax
DescriptionIf you compile the attached program an run it, you will get a range check error / crash. I narrowed the error down as far as I could, but there might still be a more simple test case.

This seems to be related to 0038122 .
Additional InformationTested with Lazarus default debug and release build modes.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

child of 0038122 feedbackSven Barth Type Helper only modifies stack copy instead of self 

Activities

Julian Puhl

2020-12-12 09:11

reporter  

HelperBug.pas (1,585 bytes)   
program HelperBug;

{$modeswitch advancedrecords}
{$modeswitch typehelpers}

type

  TTestInner = record
    A: Integer;
    B: array of Integer;
    procedure SetBWithoutHelper(Value: Integer); inline;
  end;

  TTest = record
    A: Integer;
    B: array of Integer;
    TestInner: TTestInner;
  end;

  TTestHelper = record helper for TTest
    procedure SetBWithHelper(Value: Integer); inline;
  end;

  TTestInnerHelper = record helper for TTestInner
    procedure SetBWithHelper(Value: Integer); inline; //inline is needed for error
  end;

  procedure TTestInner.SetBWithoutHelper(Value: Integer);
  begin
    B[0] := Value;
  end;

  procedure TTestInnerHelper.SetBWithHelper(Value: Integer);
  begin
    B[0] := Value;
  end;

  procedure TTestHelper.SetBWithHelper(Value: Integer);
  begin
    B[0] := Value;
  end;

var
  Test: TTest;
begin

  Test.B := nil; //Otherwise compiler warns, despite setlength initializes everything to 0 according to documentation

  //Setting lengths
  setlength(Test.B, 1);
  setlength(Test.TestInner.B, 1); //Note: Curiously compiler does NOT warn here about no initialization

  //First tests all fine
  Test.B[0] := 1;
  Test.SetBWithHelper(1);
  with Test do
    SetBWithHelper(1);

  //Still all fine here
  Test.TestInner.B[0] := 1;
  Test.TestInner.SetBWithHelper(1);
  Test.TestInner.SetBWithoutHelper(1);
  with Test.TestInner do
    SetBWithoutHelper(1);

  //Causes range check error or crashes without checks
  with Test.TestInner do
    SetBWithHelper(1);
end.
HelperBug.pas (1,585 bytes)   

Julian Puhl

2021-01-01 16:12

reporter   ~0127997

Any news on this? Also the mentioned probably related bug report 0038122 has been reopened, so maybe this bug report could be at least marked as related.

With the current revision 47932 this error still happens.

Issue History

Date Modified Username Field Change
2020-12-12 09:11 Julian Puhl New Issue
2020-12-12 09:11 Julian Puhl File Added: HelperBug.pas
2021-01-01 16:12 Julian Puhl Note Added: 0127997
2021-01-01 17:04 Sven Barth Relationship added child of 0038122