comp.lang.ada
 help / color / mirror / Atom feed
* GNAT Error message
@ 2000-12-17 18:11 Thierry&Annick
  2000-12-18  0:56 ` Robert Dewar
  2000-12-19 15:56 ` Tucker Taft
  0 siblings, 2 replies; 9+ messages in thread
From: Thierry&Annick @ 2000-12-17 18:11 UTC (permalink / raw)


Consider the following (incorrect) code "test.ada" :

generic
  type Index_Type is (<>);
package Generic_Array is
  type Instance_Type is array (Index_Type) of Integer;
  procedure Fill (This : out Instance_Type);
end Generic_Array;

package body Generic_Array is
  procedure Fill (This : out Instance_Type) is
  begin
    for Index in Index_Type loop
      This (Index) := Integer (Index - This'First);   -- Line 13
    end loop;
  end Fill;
end Generic_Array;

with Generic_Array;
procedure Check is
  type Int_Type is range 0 .. 10;
  package Int_Array is new Generic_Array (Int_Type);
begin
  null;
end Check;


The GNAT error message after gnatchop'ed (gnatchop -q -r -w) is :
test.ada:13:38: invalid operand types for operator "-"
test.ada:13:38: left operand has type "Index_Type" defined at test.ada:2

test.ada:13:38: right operand has type "Index_Type" defined at
test.ada:2
gnatmake: "check.adb" compilation error

Ok, my fault : Index_Type should be "range <>" to have a "-" operator,
but the error message is not clear.
Anybody knows what will this message be with others compilers ?






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

* Re: GNAT Error message
  2000-12-17 18:11 GNAT Error message Thierry&Annick
@ 2000-12-18  0:56 ` Robert Dewar
  2000-12-18 21:58   ` Thierry&Annick
  2000-12-19 15:56 ` Tucker Taft
  1 sibling, 1 reply; 9+ messages in thread
From: Robert Dewar @ 2000-12-18  0:56 UTC (permalink / raw)


In article <3A3D01EA.37CB440B@libertysurf.fr>,
  Thierry&Annick <tajz@libertysurf.fr> wrote:

> test.ada:13:38: invalid operand types for operator "-"
> test.ada:13:38: left operand has type "Index_Type" defined
                                                at test.ada:2
> test.ada:13:38: right operand has type "Index_Type" defined

> Ok, my fault : Index_Type should be "range <>" to have a "-"
operator,
> but the error message is not clear.
Feel free to suggest how GNAT could make this clearer (and
submit your suggestion to report@gnat.com). I don't really
see any way of making this clearer.

The compiler is telling you that there is no "-" operator
defined that would apply to the types of the operands, and
then it tells you the types of the operands, so that you
figure out the real problem (which might be that you meant
to define a "-" operator but did not, or it might be that
you accidentally typed the wrong thing as one of the operands.


Sent via Deja.com
http://www.deja.com/



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

* Re: GNAT Error message
  2000-12-18  0:56 ` Robert Dewar
@ 2000-12-18 21:58   ` Thierry&Annick
  2000-12-19  2:23     ` Ken Garlington
  2000-12-19 15:37     ` Robert Dewar
  0 siblings, 2 replies; 9+ messages in thread
From: Thierry&Annick @ 2000-12-18 21:58 UTC (permalink / raw)


Robert Dewar a �crit :

> In article <3A3D01EA.37CB440B@libertysurf.fr>,
>   Thierry&Annick <tajz@libertysurf.fr> wrote:
>
> > test.ada:13:38: invalid operand types for operator "-"
> > test.ada:13:38: left operand has type "Index_Type" defined
>                                                 at test.ada:2
> > test.ada:13:38: right operand has type "Index_Type" defined
> ...

> Feel free to suggest how GNAT could make this clearer (and
> submit your suggestion to report@gnat.com). I don't really
> see any way of making this clearer.

I suggest 'no binary operator "-" for enumeration type Index_Type'

>
>
> The compiler is telling you that there is no "-" operator

So it should tell it as you do.

I spent some time finding my error, I hope to remember it next time ...






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

* Re: GNAT Error message
  2000-12-18 21:58   ` Thierry&Annick
@ 2000-12-19  2:23     ` Ken Garlington
  2000-12-19 15:37     ` Robert Dewar
  1 sibling, 0 replies; 9+ messages in thread
From: Ken Garlington @ 2000-12-19  2:23 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1529 bytes --]


"Thierry&Annick" <tajz@libertysurf.fr> wrote in message
news:3A3E888E.E897AF0F@libertysurf.fr...
: Robert Dewar a �crit :
:
: > In article <3A3D01EA.37CB440B@libertysurf.fr>,
: >   Thierry&Annick <tajz@libertysurf.fr> wrote:
: >
: > > test.ada:13:38: invalid operand types for operator "-"
: > > test.ada:13:38: left operand has type "Index_Type" defined
: >                                                 at test.ada:2
: > > test.ada:13:38: right operand has type "Index_Type" defined
: > ...
:
: > Feel free to suggest how GNAT could make this clearer (and
: > submit your suggestion to report@gnat.com). I don't really
: > see any way of making this clearer.
:
: I suggest 'no binary operator "-" for enumeration type Index_Type'

Which Index_Type? Seems like the compiler should identify this more clearly
(e.g. by noting that it was the one declared at "test.ada:2").

And what if one (or more) binary operators "-" had been declared involving
Index_Type, but none had *both* a left and right operand of Index_Type
(i.e., one of the operands was a non-Index_Type in each case)? Seems like
the compiler should point out that it couldn't find a binary operator "-"
where the specific left and right operand types used didn't match any of the
"-" visible at the point of use.

And, in fact, this is exactly what the compiler did!

: >
: >
: > The compiler is telling you that there is no "-" operator
:
: So it should tell it as you do.
:
: I spent some time finding my error, I hope to remember it next time ...
:
:
:





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

* Re: GNAT Error message
  2000-12-18 21:58   ` Thierry&Annick
  2000-12-19  2:23     ` Ken Garlington
@ 2000-12-19 15:37     ` Robert Dewar
  1 sibling, 0 replies; 9+ messages in thread
From: Robert Dewar @ 2000-12-19 15:37 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1361 bytes --]

In article <3A3E888E.E897AF0F@libertysurf.fr>,
  Thierry&Annick <tajz@libertysurf.fr> wrote:
> Robert Dewar a �crit :
>
> > In article <3A3D01EA.37CB440B@libertysurf.fr>,
> >   Thierry&Annick <tajz@libertysurf.fr> wrote:
> >
> > > test.ada:13:38: invalid operand types for operator "-"
> > > test.ada:13:38: left operand has type "Index_Type"
defined
> >                                                 at
test.ada:2
> > > test.ada:13:38: right operand has type "Index_Type"
defined
> > ...
>
> > Feel free to suggest how GNAT could make this clearer (and
> > submit your suggestion to report@gnat.com). I don't really
> > see any way of making this clearer.
>
> I suggest 'no binary operator "-" for enumeration type
> Index_Type'


Well the error messages that it giving now give this
information in a much more precise form, by telling you
that there is no "-" operator for the particular types
you used, and then telling you what those types are.
So in fact your suggestion here would give less information.

What would be useful is to explain what was unclear about
the original message. We want to make the message as clear
as possible, but we don't want to lose information doing do
(indeed the addition of the operand types in the error messages
was done fairly recently, and has proved extremely helpful).



Sent via Deja.com
http://www.deja.com/



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

* Re: GNAT Error message
  2000-12-17 18:11 GNAT Error message Thierry&Annick
  2000-12-18  0:56 ` Robert Dewar
@ 2000-12-19 15:56 ` Tucker Taft
  2000-12-20  0:38   ` Robert Dewar
  1 sibling, 1 reply; 9+ messages in thread
From: Tucker Taft @ 2000-12-19 15:56 UTC (permalink / raw)


Thierry&Annick wrote:
> The GNAT error message after gnatchop'ed (gnatchop -q -r -w) is :
> test.ada:13:38: invalid operand types for operator "-"
> test.ada:13:38: left operand has type "Index_Type" defined at test.ada:2
> 
> test.ada:13:38: right operand has type "Index_Type" defined at
> test.ada:2
> gnatmake: "check.adb" compilation error
> 
> Ok, my fault : Index_Type should be "range <>" to have a "-" operator,
> but the error message is not clear.
> Anybody knows what will this message be with others compilers ?

Here is the "AdaMagic" error message, interspersed in the listing:

  ...
   13       This (Index) := Integer (Index - This'First);   -- Line 13
                                            *
*****Error: LRM:8.4(1) Binary operator "-" between Index_Type and Index_Type
*****        not directly visible, use clause or conversion might be needed
   14     end loop;
  ...

Not clearly better or worse, in my view, than the GNAT error message.

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Commercial Division, AverStar (formerly Intermetrics)
(http://www.averstar.com/services/IT_consulting.html)  Burlington, MA  USA



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

* Re: GNAT Error message
  2000-12-19 15:56 ` Tucker Taft
@ 2000-12-20  0:38   ` Robert Dewar
  2000-12-20 17:44     ` Larry Kilgallen
  0 siblings, 1 reply; 9+ messages in thread
From: Robert Dewar @ 2000-12-20  0:38 UTC (permalink / raw)


In article <3A3F854A.4AAC16EB@averstar.com>,
  Tucker Taft <stt@averstar.com> wrote:
> Here is the "AdaMagic" error message, interspersed in the
listing:
>
>   ...
>    13       This (Index) := Integer (Index - This'First);
-- Line 13
>                                             *
> *****Error: LRM:8.4(1) Binary operator "-" between Index_Type
and Index_Type
> *****        not directly visible, use clause or conversion
might be needed
>    14     end loop;
>   ...
>
> Not clearly better or worse, in my view, than the GNAT error
message.

Hmmm! would you clearly distinguish if more than one Index_Type
was in scope -- we find the location references to the
declaration very useful in GNAT.


Sent via Deja.com
http://www.deja.com/



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

* Re: GNAT Error message
  2000-12-20  0:38   ` Robert Dewar
@ 2000-12-20 17:44     ` Larry Kilgallen
  2000-12-20 20:36       ` Robert Dewar
  0 siblings, 1 reply; 9+ messages in thread
From: Larry Kilgallen @ 2000-12-20 17:44 UTC (permalink / raw)


In article <91ov30$s9g$1@nnrp1.deja.com>, Robert Dewar <robert_dewar@my-deja.com> writes:
> In article <3A3F854A.4AAC16EB@averstar.com>,
>   Tucker Taft <stt@averstar.com> wrote:
>> Here is the "AdaMagic" error message, interspersed in the
> listing:
>>
>>   ...
>>    13       This (Index) := Integer (Index - This'First);
> -- Line 13
>>                                             *
>> *****Error: LRM:8.4(1) Binary operator "-" between Index_Type
> and Index_Type
>> *****        not directly visible, use clause or conversion
> might be needed
>>    14     end loop;
>>   ...
>>
>> Not clearly better or worse, in my view, than the GNAT error
> message.
> 
> Hmmm! would you clearly distinguish if more than one Index_Type
> was in scope -- we find the location references to the
> declaration very useful in GNAT.

While a location reference to the declaration sounds quite helpful
in general, I would suggest that it be suppressed in the case of
those who have more than one Index_Type in scope, giving them some
encouragement to change their ways.

This is for the (admittedly low probability) chance that _I_
might have to maintain their code some day :-)



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

* Re: GNAT Error message
  2000-12-20 17:44     ` Larry Kilgallen
@ 2000-12-20 20:36       ` Robert Dewar
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 2000-12-20 20:36 UTC (permalink / raw)


In article <V5oHw+onke6g@eisner.decus.org>,
  Kilgallen@eisner.decus.org.nospam (Larry Kilgallen) wrote:
> While a location reference to the declaration sounds quite
> helpful in general, I would suggest that it be suppressed in
> the case of those who have more than one Index_Type in scope,
> giving them some encouragement to change their ways.
>
> This is for the (admittedly low probability) chance that _I_
> might have to maintain their code some day :-)

Sounds like you might like the new warning flag -gnatwh in GNAT
that prevents any hiding of names :-)


Sent via Deja.com
http://www.deja.com/



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

end of thread, other threads:[~2000-12-20 20:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-17 18:11 GNAT Error message Thierry&Annick
2000-12-18  0:56 ` Robert Dewar
2000-12-18 21:58   ` Thierry&Annick
2000-12-19  2:23     ` Ken Garlington
2000-12-19 15:37     ` Robert Dewar
2000-12-19 15:56 ` Tucker Taft
2000-12-20  0:38   ` Robert Dewar
2000-12-20 17:44     ` Larry Kilgallen
2000-12-20 20:36       ` Robert Dewar

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