comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
Subject: Re: Rosetta Code task Proper divisors fails to compile
Date: Wed, 26 Jul 2023 21:57:37 +0200	[thread overview]
Message-ID: <u9rtrh$1hutd$1@dont-email.me> (raw)
In-Reply-To: <c9868ca1-84c8-41d9-be3c-bd58432e87b5n@googlegroups.com>

On 2023-07-26 20:30, Kenneth Wolcott wrote:
> 
>    Thank you for your suggestion.  Doesn't seem to have any effect.

Interesting. I get the same results with GNAT 12.

Looking more closely at the code, I think the error, while its msg is 
misleading, is correct. A function that returns a limited type can only return 
an aggregate, a function call, or an object declared by an extended return 
statement. The generic formal object None is none of these.

Changing the generic parameter to a function

    with function None return Result_Type;

makes the code correct. You need to change the definition of Empty in 
Proper_Divisors

       function Empty return Pos_Arr is (1 .. 0 => <>);

and create a function to supply for the 2nd instantiation

       function None return Natural is (0);
...
       package Divisor_Count is new Generic_Divisors
	(Result_Type => Natural, None => None, One => Cnt, Add =>  "+");

and then it compiles and runs.

Another possibility is to make Result_Type simply private, though that is 
slightly less general. That may be how the OP got the code to compile and run. 
It might be that limited was added later because the OP saw that it could be, 
and never tested the change.

-- 
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus
54

  reply	other threads:[~2023-07-26 19:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26  4:49 Rosetta Code task Proper divisors fails to compile Kenneth Wolcott
2023-07-26  8:36 ` Jeffrey R.Carter
2023-07-26 18:30   ` Kenneth Wolcott
2023-07-26 19:57     ` Jeffrey R.Carter [this message]
2023-07-26 22:26       ` Kenneth Wolcott
replies disabled

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