"return type does not match" but they really seem to match, unless I went blind [I AM blind...]

Hi,
I have the following message:

Card_package.adb:39:18: error: not type conformant with declaration at card_package.ads:13
card_package.adb:39:18: error: return type does not match
gnatmake: "card_package.adb" compilation error

However I can’t see the difference with the specifications. Both return types are card_number_type as far as I can see. No subtype range.
specifiations:

type Card_Deck is limited private;
subtype Card_number_type is Natural range 0..Max_Card_Number;
function Number_Of_Card (D: Card_Deck) return Card_number_type; -- HERE

private
	type Card_Deck (Number: Card_number_type := Max_card_number) is record
		List: Card_list (1..Number);
	end record;

body:

function Number_Of_Card (D: Card_Deck) return Card_number_type is (D.Number);

Minimal code:

pragma Ada_2022;
pragma Extensions_Allowed (On);
with Ada.Text_IO, Ada.Numerics.Discrete_Random, Ada.Strings.Fixed, Ada.Characters.Handling;
with Ada.Strings.Text_Buffers;

 package Card_Package is
	type Cards is private with Put_Image => My_Put_Image;
	type Card_Deck is limited private;
	Empty_Deck, Full_Deck: exception;
   	procedure My_Put_Image (Output : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; Value: Cards);
	Max_Card_Number : constant := 52;
	subtype Card_number_type is Natural range 0..Max_Card_Number;
	function Number_Of_Card (D: Card_Deck) return Card_number_type;
	function Default_list (Card_number: Card_number_type) return Card_Deck;
private
	type Card_list is array (Natural range <>) of Cards;
	type Card_Deck (Number: Card_number_type := Max_card_number) is record
		List: Card_list (1..Number);
	end record;
	type Card_Suite is (Clubs,Spades,Hearts,Diamonds);
	type Card_Value is (Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Ace,Jack,Queen,King);
	type Cards is record
		Suite: Card_Suite;
		Value: Card_Value;
	end record;
end Card_Package;

package body Card_Package is
	function Number_Of_Card (D: Card_Deck) return Card_number_type is (D.Number);
	procedure My_Put_Image (Output : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; Value: Cards) is
		use Ada.Text_IO, Ada.Strings.Fixed, Ada.Characters.Handling;
	begin
		Put(Trim(To_Lower(Value.Suite'Image),Ada.Strings.Both)); Put(" of "); Put(Trim(To_Lower(Value.Value'Image),Ada.Strings.Both)); 
	end My_Put_Image;
	function Default_list (Card_number: Card_number_type) return Card_List is
		package RSP is new Ada.Numerics.Discrete_Random (Card_suite);
		package RVP is new Ada.Numerics.Discrete_Random (Card_value);
		use RSP, RVP;
		Value_Gen: RVP.Generator;
		Suite_Gen: RSP.Generator;
		type Array_boolean is array (Card_suite,Card_Value) of Boolean;
		Cards_done: Array_boolean := (others => (others => False));
		Random_Card: Cards;
		List: Card_List (1..Card_Number);
	begin
		Reset(Value_Gen); Reset(Suite_Gen);
		for I in 1..Card_Number loop
			loop
				Random_Card := (Random(Suite_Gen),Random(Value_Gen));
				exit when not Cards_Done (Random_Card.Suite,Random_Card.Value);
            end loop;
            List(I) := Random_Card;
            Cards_Done (Random_Card.Suite, Random_Card.Value) := true;
		end loop;
		return List;
	end Default_list;
end Card_Package;

Is Default_List supposed to return a Card_List or a Card_Deck?

2 Likes

For a bit more clarification on Simon’s answer, your package spec has

which specifies a return type of Card_Deck, while your body has

which specifies a return type of Card_List.

These do not match.

Dammit, I read the line 10 times and did not see this ! I really am blind !