mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-12 22:49:34 +02:00
* fix #32034 and fix #39656: in a for-in-loop with an array constructor enforce the type of the loop variable for the elements
+ added tests
This commit is contained in:
parent
1180589046
commit
815734c47a
@ -937,6 +937,8 @@ implementation
|
||||
end
|
||||
else
|
||||
begin
|
||||
if is_array_constructor(expr.resultdef) then
|
||||
tarrayconstructornode(expr).force_type(hloopvar.resultdef);
|
||||
// search for operator first
|
||||
pd:=search_enumerator_operator(expr.resultdef, hloopvar.resultdef);
|
||||
// if there is no operator then search for class/object enumerator method
|
||||
|
14
tests/webtbs/tw32034.pp
Normal file
14
tests/webtbs/tw32034.pp
Normal file
@ -0,0 +1,14 @@
|
||||
program tw32034;
|
||||
|
||||
{$H-}
|
||||
|
||||
var
|
||||
s: String;
|
||||
begin
|
||||
for s in (['1char','2chars']) do begin
|
||||
WriteLn(s);
|
||||
if (s <> '1char') and (s <> '2chars') then
|
||||
Halt(1);
|
||||
end;
|
||||
end.
|
||||
|
24
tests/webtbs/tw39656.pp
Normal file
24
tests/webtbs/tw39656.pp
Normal file
@ -0,0 +1,24 @@
|
||||
program tw39656;
|
||||
|
||||
uses
|
||||
sysutils,math;
|
||||
var
|
||||
r: double;
|
||||
ar: array of double = (0.001, 0.5, 0.7, 0.999);
|
||||
idx: LongInt;
|
||||
begin
|
||||
{Write('good:');
|
||||
for r in ar do Write(FloatToStr(r), ' ');
|
||||
Writeln;}
|
||||
|
||||
//Write('bad:');
|
||||
idx:=0;
|
||||
for r in [0.001, 0.5, 0.7, 0.999] do begin
|
||||
//Write(FloatToStr(r), ' ');
|
||||
if not SameValue(r,ar[idx]) then
|
||||
Halt(idx+1);
|
||||
Inc(idx);
|
||||
end;
|
||||
//Writeln;
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user