View Issue Details

IDProjectCategoryView StatusLast Update
0037338FPCCompilerpublic2020-07-12 16:51
ReporterRunar Tenfjord Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionduplicate 
Platform32bitOSWindows 
Product Version3.2.0 
Summary0037338: Loop over anonymous array cap string length to first element
DescriptionA simple loop over anonymous array of strings will cap the string length
to the length of the first element.

This code compiles without any warning.

In addition the $H+ mode is selected and it seems ShortString is returned.
Steps To ReproduceCode:

program stringlooptest;
{$mode objfpc}{$H+}
var
  name : string;
begin
  for name in ['project','customer','supplier'] do
    WriteLn(name);
end.

Returns:
project
custome
supplie

e.g. last element has capped length.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Relationships

duplicate of 0032034 new Wrong code generated for literal array of string in for-in loop 

Activities

nanobit

2020-07-12 14:06

reporter   ~0123925

Last edited: 2020-07-12 14:12

View 2 revisions

workaround with typecasting:

type ta = array of string;
var name : string;
begin
for name in ta(['project','customer','supplier']) do
// or for name in [string('project'), string('customer'), string('supplier')] do
    WriteLn(name);
end.

Sven Barth

2020-07-12 16:51

manager   ~0123934

Sorry, I hadn't seen that this was already reported.

Issue History

Date Modified Username Field Change
2020-07-12 13:01 Runar Tenfjord New Issue
2020-07-12 14:06 nanobit Note Added: 0123925
2020-07-12 14:12 nanobit Note Edited: 0123925 View Revisions
2020-07-12 16:51 Sven Barth Assigned To => Sven Barth
2020-07-12 16:51 Sven Barth Status new => resolved
2020-07-12 16:51 Sven Barth Resolution open => duplicate
2020-07-12 16:51 Sven Barth FPCTarget => -
2020-07-12 16:51 Sven Barth Note Added: 0123934
2020-07-12 16:51 Sven Barth Relationship added duplicate of 0032034