View Issue Details

IDProjectCategoryView StatusLast Update
0035476FPCDocumentationpublic2019-05-02 23:47
ReporterBart BroersmaAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386OSWindowsOS Version10
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0035476: Loop control vriable in a procedure must be local to that procedure, but this is not documented.
DescriptionA loop control variable in a procedure must be local to that procedure.
It is the same in Delphi.
The documentation does not mention this though.
Steps To Reproduceprogram test;

{$ifdef fpc}
{$mode delphi}
{$h+}
{$endif}

procedure Proc;
var
  i: integer;
  procedure Nested;
  //var
  // i: integer;
  begin
    for i := 1 to 2 do ;
  end;
begin
end;

begin
end.

The compiler complains: "test.pas(15,9) Error: Illegal counter variable".
(Delphi says: "test.pas(15) Error: For loop control variable must be simple local variable.")
Additional InformationReported in https://forum.lazarus.freepascal.org/index.php/topic,45270.msg319903.html#msg319903
TagsNo tags attached.
Fixed in Revision1603
FPCOldBugId
FPCTarget3.2.0
Attached Files

Activities

Michael Van Canneyt

2019-05-02 23:02

administrator   ~0115965

Documented. Note that this is only for nested procedures. The following will work:
program test;

{$ifdef fpc}
{$mode delphi}
{$h+}
{$endif}

var
  i: integer;

procedure Nested;

begin
  for i := 1 to 2 do ;
end;

begin
end.

Bart Broersma

2019-05-02 23:47

reporter   ~0115966

Thanks.

Issue History

Date Modified Username Field Change
2019-05-02 22:49 Bart Broersma New Issue
2019-05-02 22:49 Bart Broersma Status new => assigned
2019-05-02 22:49 Bart Broersma Assigned To => Michael Van Canneyt
2019-05-02 23:02 Michael Van Canneyt Status assigned => resolved
2019-05-02 23:02 Michael Van Canneyt Resolution open => fixed
2019-05-02 23:02 Michael Van Canneyt Fixed in Version => 3.3.1
2019-05-02 23:02 Michael Van Canneyt Fixed in Revision => 1603
2019-05-02 23:02 Michael Van Canneyt FPCTarget => 3.2.0
2019-05-02 23:02 Michael Van Canneyt Note Added: 0115965
2019-05-02 23:47 Bart Broersma Status resolved => closed
2019-05-02 23:47 Bart Broersma Note Added: 0115966