porton
porton

Reputation: 5827

What is the error in this Ada program?

What is the error in this Ada2012 program?

with Ada.Iterator_Interfaces;

package My is

   type Cursor is private;

   function Has_Element (Position: Cursor) return Boolean;

   package Base_Iterators is new Ada.Iterator_Interfaces(Cursor, Has_Element);

   type Bindings_Iterator is new Base_Iterators.Forward_Iterator with private;

   overriding function First (Object: Bindings_Iterator) return Cursor;

   overriding function Next (Object: Bindings_Iterator; Position: Cursor) return Cursor;

private

   type Iterated_Object is access all Integer;

   type Cursor is new Iterated_Object;

   type Bindings_Iterator is new Base_Iterators.Forward_Iterator with null record;

end My;

Attempt to check the syntax and semantics:

$ gnatgcc -gnat2012 -c my.ads 
my.ads:23:09: type must be declared abstract or "First" overridden
my.ads:23:09: "First" has been inherited from subprogram at a-iteint.ads:26, instance at line 9

As far as I understand First is overridden by me. I don't get what the compiler complaints for.

Upvotes: 0

Views: 605

Answers (1)

egilhh
egilhh

Reputation: 6430

The error comes from Cursor being a privately derived access type. Changing it to

type Cursor is access all Integer;

removes the error, as does changing it to a record type or numeric type. Moving the full definition of Iterated_Object and Cursor to the public view also removes the error.

I'm thinking you have stumbled upon a compiler error.

Upvotes: 3

Related Questions