View Issue Details

IDProjectCategoryView StatusLast Update
0032034FPCCompilerpublic2020-07-12 16:51
ReporterMario Ray Mahardhika Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86_64OSlinux 
Product Version3.1.1 
Summary0032034: Wrong code generated for literal array of string in for-in loop
DescriptionCurrently, the compiler only considers the first element to determine subsequent elements length, which is of course wrong. However, when the literal array is cast into dynamic array of string, the generated code is correct.
Steps To ReproduceCompile the following program:

var
  s: String;
begin
  for s in (['1char','2chars']) do
    WriteLn(s);
end.

it will output:
1char
2char

instead of the expected:
1char
2chars
Additional InformationModify above program to:

uses
  SysUtils;
type
  TStringArray = specialize TArray<String>;
var
  s: String;
begin
  for s in TStringArray(['1char','2chars']) do
    WriteLn(s);
end.

and the output will be as expected:
1char
2chars
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

has duplicate 0037338 resolvedSven Barth Loop over anonymous array cap string length to first element 

Activities

Thaddy de Koning

2017-06-19 23:11

reporter   ~0101228

Last edited: 2017-06-19 23:15

View 4 revisions

Well,this is also enough:
var
  a: array of string;
  s: String;
begin
   a := ['1char','2chars'];
  for s in a do
    WriteLn(s);
    readln
end.

Which has the expected output.

But I can confirm this behavior.
I am not sure if your chosen assumption about the syntax is correct.

Issue History

Date Modified Username Field Change
2017-06-18 00:08 Mario Ray Mahardhika New Issue
2017-06-19 23:11 Thaddy de Koning Note Added: 0101228
2017-06-19 23:12 Thaddy de Koning Note Edited: 0101228 View Revisions
2017-06-19 23:14 Thaddy de Koning Note Edited: 0101228 View Revisions
2017-06-19 23:15 Thaddy de Koning Note Edited: 0101228 View Revisions
2020-07-12 16:51 Sven Barth Relationship added has duplicate 0037338