comp.lang.ada
 help / color / mirror / Atom feed
* Should this be legal?
@ 2001-03-22 10:13 Oliver Kellogg
  2001-03-22 11:15 ` Martin Dowie
  2001-03-22 16:29 ` Mark Lundquist
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Kellogg @ 2001-03-22 10:13 UTC (permalink / raw)


Hello Ada experts,

The full declaration of the Derived type looks different than
the partial view (Base_2 vs. Base(2))

Should this be legal?
Rational Apex 3.2.0b and GNAT 3.13p both accept it.
(However, both compilers tend to have problems with this
type of construction - especially in more complicated contexts.)

But then, if Base_2 and Base(2) are supposedly interchangeable,
how come the function Legal is accepted but function Illegal is
refused ("constraint not allowed here") ?

Thanks,

Oliver M. Kellogg


-- subtyped_discriminant.ads

package Subtyped_Discriminant is

   type Base (N : Integer) is tagged null record;

   subtype Base_2 is Base (2);

   type Derived is new Base_2 with private;

private

   type Derived is new Base (2) with null record;

   -- However,

   function Legal return Base_2;

   function Illegal return Base (2);

end Subtyped_Discriminant;







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

* Re: Should this be legal?
  2001-03-22 10:13 Should this be legal? Oliver Kellogg
@ 2001-03-22 11:15 ` Martin Dowie
  2001-03-22 14:21   ` Oliver Kellogg
  2001-03-22 16:29 ` Mark Lundquist
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Dowie @ 2001-03-22 11:15 UTC (permalink / raw)


ObjectAda 7.2 SE returns the following errors:
subtype_discriminant.ads: Error: line 15 col 13 LRM:3.9.2(13), a primitive
subprogram of a tagged type may not be declared after the type is frozen

subtype_discriminant.ads: Error: line 15 col 13 LRM:3.9.2(10), return
subtype does not statically match the first subtype of the tagged type

subtype_discriminant.ads: Error: line 17 col 33 LRM:3.2.2(4), Only a
subtype_mark is permitted in this context; no constraint is allowed,
ignoring constraint

subtype_discriminant.ads: Error: line 17 col 13 LRM:3.9.2(13), a primitive
subprogram of a tagged type may not be declared after the type is frozen


Oliver Kellogg <oliver.kellogg@vs.dasa.de> wrote in message
news:99cjt2$v9g@newsserv.vs.dasa.de...
> Hello Ada experts,
>
> The full declaration of the Derived type looks different than
> the partial view (Base_2 vs. Base(2))
>
> Should this be legal?
> Rational Apex 3.2.0b and GNAT 3.13p both accept it.
> (However, both compilers tend to have problems with this
> type of construction - especially in more complicated contexts.)
>
> But then, if Base_2 and Base(2) are supposedly interchangeable,
> how come the function Legal is accepted but function Illegal is
> refused ("constraint not allowed here") ?
>
> Thanks,
>
> Oliver M. Kellogg
>
>
> -- subtyped_discriminant.ads
>
> package Subtyped_Discriminant is
>
>    type Base (N : Integer) is tagged null record;
>
>    subtype Base_2 is Base (2);
>
>    type Derived is new Base_2 with private;
>
> private
>
>    type Derived is new Base (2) with null record;
>
>    -- However,
>
>    function Legal return Base_2;
>
>    function Illegal return Base (2);
>
> end Subtyped_Discriminant;
>
>
>
>





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

* Re: Should this be legal?
  2001-03-22 11:15 ` Martin Dowie
@ 2001-03-22 14:21   ` Oliver Kellogg
  0 siblings, 0 replies; 5+ messages in thread
From: Oliver Kellogg @ 2001-03-22 14:21 UTC (permalink / raw)


In message <3ab9dcf8$1@pull.gecm.com>, Martin Dowie wrote:

>ObjectAda 7.2 SE returns the following errors:
> [...]

Thanks for trying this out.
For better top-down reading I had put the methods in the private part,
in the original code they were public. (The methods aren't the point
anyway - you can leave them away altogether)

-- Oliver






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

* Re: Should this be legal?
  2001-03-22 10:13 Should this be legal? Oliver Kellogg
  2001-03-22 11:15 ` Martin Dowie
@ 2001-03-22 16:29 ` Mark Lundquist
  2001-03-22 16:51   ` Robert A Duff
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Lundquist @ 2001-03-22 16:29 UTC (permalink / raw)



Oliver Kellogg <oliver.kellogg@vs.dasa.de> wrote in message
news:99cjt2$v9g@newsserv.vs.dasa.de...
> Hello Ada experts,
>
> The full declaration of the Derived type looks different than
> the partial view (Base_2 vs. Base(2))
>
> Should this be legal?
> Rational Apex 3.2.0b and GNAT 3.13p both accept it.

Not as you posted it (but I think you cleared this up in another post)

> (However, both compilers tend to have problems with this
> type of construction - especially in more complicated contexts.)

I believe your completion of type Derived is legal, but I'm not a language
lawyer... However, it seems like all the completion rules in 7.3 would
really be unnecessary if the partial and full views were required to "look
the same"...

>
> But then, if Base_2 and Base(2) are supposedly interchangeable,
> how come the function Legal is accepted but function Illegal is
> refused ("constraint not allowed here") ?

Because the construct that follows the "return" must be a subtype_mark, that
is, a name that denotes a (named) subtype (i.e. either the "first subtype"
of a type, or a subtype defined by a subtype declaration).  What you have
there is actually just a syntax error.

Mark Lundquist
Rational Software






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

* Re: Should this be legal?
  2001-03-22 16:29 ` Mark Lundquist
@ 2001-03-22 16:51   ` Robert A Duff
  0 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2001-03-22 16:51 UTC (permalink / raw)


"Mark Lundquist" <mark@rational.com> writes:

> I believe your completion of type Derived is legal, but I'm not a language
> lawyer... 

I *am* a language lawyer, but I don't know the right answer.
I would have to go study the conformance rules.

>...However, it seems like all the completion rules in 7.3 would
> really be unnecessary if the partial and full views were required to "look
> the same"...

But we don't want them to *be* the same.  Eg:

    type T is new Ancestor with private;
private
    type T is new Parent with record ...

is legal (and useful), if Parent is derived from Ancestor.

> > But then, if Base_2 and Base(2) are supposedly interchangeable,
> > how come the function Legal is accepted but function Illegal is
> > refused ("constraint not allowed here") ?
> 
> Because the construct that follows the "return" must be a subtype_mark, that
> is, a name that denotes a (named) subtype (i.e. either the "first subtype"
> of a type, or a subtype defined by a subtype declaration).  What you have
> there is actually just a syntax error.

Right -- it's just a syntax error.  But Oliver Kellogg asked *why*.  I'm
not sure, but an early version of Ada (1981?) allowed it.  Probably
something to do with when the expressions are elaborated.

- Bob




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

end of thread, other threads:[~2001-03-22 16:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-22 10:13 Should this be legal? Oliver Kellogg
2001-03-22 11:15 ` Martin Dowie
2001-03-22 14:21   ` Oliver Kellogg
2001-03-22 16:29 ` Mark Lundquist
2001-03-22 16:51   ` Robert A Duff

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