synopse / mORMot2

OpenSource RESTful ORM/SOA/MVC Framework for Delphi and FreePascal
https://synopse.info
Other
531 stars 132 forks source link

Exception in IDocList #322

Closed zen010101 closed 2 days ago

zen010101 commented 3 days ago
const
  j = '[{"id":"f7518487-6e95-4c90-8438-a6b48d6a8b5f","name":"user","phones":[{"type":"mobile","number":"123-456-789"}]}]';
var
  d1, d2: IDocDict;
begin
  for d1 in DocList(j) do
    for d2 in d1.L['phones'] do // Exception is here
      writeln(d2['number']);
end;    

Compiler: FPC 3.3.1-16402-g99943610cb-dirty OS: Windows 11

synopse commented 3 days ago

I guess this should be first asked on the forum, to refine any bug search.

Sounds like a compiler bug to me. No problem with Delphi running your code.

If we write

  for d1 in DocList(j) do
  begin
   phones := d1.L['phones'];
    for d2 in phones do 
      writeln(d2['number']);
  end;

there is no problem with FPC any more.

I have added some tests about this pattern.