comp.lang.ada
 help / color / mirror / Atom feed
* Why this program does not compile? (iterators)
@ 2014-08-22 17:18 Victor Porton
  2014-08-22 23:39 ` Randy Brukardt
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Victor Porton @ 2014-08-22 17:18 UTC (permalink / raw)


Why this program does not compile?

gnatgcc -c -g -O2 -gnat2012 -g -O0 -gnato -fstack-check -gnatVa special_test.adb
<built-in>: In function ‘Special_Test’:
<built-in>: error: aggregate value used where an integer was expected

with Ada.Iterator_Interfaces;

procedure Special_Test is

   type My_Description_Cursor is null record;
   
   function Has_Element (Position: My_Description_Cursor) return Boolean is (False);

   package My_Description_Iterators is new Ada.Iterator_Interfaces(My_Description_Cursor, Has_Element);

   type My_Description_Iterator is new My_Description_Iterators.Forward_Iterator with null record;
   
   overriding function First (Object: My_Description_Iterator) return My_Description_Cursor is (null record);
   overriding function Next (Object: My_Description_Iterator; Position: My_Description_Cursor) return My_Description_Cursor is (null record);

   My_Iterator: My_Description_Iterator;

begin
   for C in My_Iterator loop
      null;
   end loop;
end;


-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why this program does not compile? (iterators)
  2014-08-22 17:18 Why this program does not compile? (iterators) Victor Porton
@ 2014-08-22 23:39 ` Randy Brukardt
  2014-08-23  4:56   ` Victor Porton
  2014-08-23  0:15 ` Egil H H
  2016-04-22 11:14 ` mockturtle
  2 siblings, 1 reply; 6+ messages in thread
From: Randy Brukardt @ 2014-08-22 23:39 UTC (permalink / raw)


Looks OK to me, probably a compiler bug of some sort. - Randy.

"Victor Porton" <porton@narod.ru> wrote in message 
news:lt7u1i$6bn$1@speranza.aioe.org...
> Why this program does not compile?
>
> gnatgcc -c -g -O2 -gnat2012 -g -O0 -gnato -fstack-check -gnatVa 
> special_test.adb
> <built-in>: In function 'Special_Test':
> <built-in>: error: aggregate value used where an integer was expected
>
> with Ada.Iterator_Interfaces;
>
> procedure Special_Test is
>
>   type My_Description_Cursor is null record;
>
>   function Has_Element (Position: My_Description_Cursor) return Boolean is 
> (False);
>
>   package My_Description_Iterators is new 
> Ada.Iterator_Interfaces(My_Description_Cursor, Has_Element);
>
>   type My_Description_Iterator is new 
> My_Description_Iterators.Forward_Iterator with null record;
>
>   overriding function First (Object: My_Description_Iterator) return 
> My_Description_Cursor is (null record);
>   overriding function Next (Object: My_Description_Iterator; Position: 
> My_Description_Cursor) return My_Description_Cursor is (null record);
>
>   My_Iterator: My_Description_Iterator;
>
> begin
>   for C in My_Iterator loop
>      null;
>   end loop;
> end;
>
>
> -- 
> Victor Porton - http://portonvictor.org 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why this program does not compile? (iterators)
  2014-08-22 17:18 Why this program does not compile? (iterators) Victor Porton
  2014-08-22 23:39 ` Randy Brukardt
@ 2014-08-23  0:15 ` Egil H H
  2014-08-23  0:31   ` Adam Beneschan
  2016-04-22 11:14 ` mockturtle
  2 siblings, 1 reply; 6+ messages in thread
From: Egil H H @ 2014-08-23  0:15 UTC (permalink / raw)


On Friday, August 22, 2014 7:18:45 PM UTC+2, Victor Porton wrote:
> Why this program does not compile?
> 
>    overriding function First (Object: My_Description_Iterator) return My_Description_Cursor is (null record);
> 
>    overriding function Next (Object: My_Description_Iterator; Position: My_Description_Cursor) return My_Description_Cursor is (null record);
> 
> 

A result of an expression function should be within parenthesis, an aggregate should as well. Try double parenthesis to return an aggregate from an expression function.
The error message is weird, though.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why this program does not compile? (iterators)
  2014-08-23  0:15 ` Egil H H
@ 2014-08-23  0:31   ` Adam Beneschan
  0 siblings, 0 replies; 6+ messages in thread
From: Adam Beneschan @ 2014-08-23  0:31 UTC (permalink / raw)


On Friday, August 22, 2014 5:15:42 PM UTC-7, Egil H H wrote:
> On Friday, August 22, 2014 7:18:45 PM UTC+2, Victor Porton wrote:
> > Why this program does not compile?
> 
> >    overriding function First (Object: My_Description_Iterator) return My_Description_Cursor is (null record);

> >    overriding function Next (Object: My_Description_Iterator; Position: My_Description_Cursor) return My_Description_Cursor is (null record);

> A result of an expression function should be within parenthesis, an aggregate should as well. Try double parenthesis to return an aggregate from an expression function.

That doesn't make the error go away.  Even making the First and Next functions normal functions, instead of expression functions, doesn't fix the problem.  The problem appears to be with the "for" statement: comment that out, and there's no more error (even with only single parentheses around "null record", which I think is a syntax error that the compiler should not be accepting).

I'd say that if the compiler is displaying "<built-in>" where it normally displays a source file name, something has gone very haywire.

                            -- Adam



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why this program does not compile? (iterators)
  2014-08-22 23:39 ` Randy Brukardt
@ 2014-08-23  4:56   ` Victor Porton
  0 siblings, 0 replies; 6+ messages in thread
From: Victor Porton @ 2014-08-23  4:56 UTC (permalink / raw)


Randy Brukardt wrote:

> Looks OK to me, probably a compiler bug of some sort. - Randy.

I've reported the bug:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62236

-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why this program does not compile? (iterators)
  2014-08-22 17:18 Why this program does not compile? (iterators) Victor Porton
  2014-08-22 23:39 ` Randy Brukardt
  2014-08-23  0:15 ` Egil H H
@ 2016-04-22 11:14 ` mockturtle
  2 siblings, 0 replies; 6+ messages in thread
From: mockturtle @ 2016-04-22 11:14 UTC (permalink / raw)


Although this thread is almost one year old, I would like to add my 2-cent experience (I just tripped on this bug), for the sake of historical record.

It actually seems that it is the "for" construction. I tried to use the iterator "by hand" (calling First at the beginning and then running a while loop with Next at the end) and everything seems to work.

In another case, I had a loop similar to

  for I in Object.Iterate loop
      X := Fun(I);

  end loop;

and I got the warning "X is read but never assigned."  It looks like another for-related bug. 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-22 11:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-22 17:18 Why this program does not compile? (iterators) Victor Porton
2014-08-22 23:39 ` Randy Brukardt
2014-08-23  4:56   ` Victor Porton
2014-08-23  0:15 ` Egil H H
2014-08-23  0:31   ` Adam Beneschan
2016-04-22 11:14 ` mockturtle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox