comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de>
Subject: Re: Operation can be dispatching in only one type
Date: Wed, 02 Dec 2009 01:32:23 +0100
Date: 2009-12-02T01:32:27+01:00	[thread overview]
Message-ID: <4b15b59b$0$7632$9b4e6d93@newsspool1.arcor-online.net> (raw)
In-Reply-To: <nospam-ABB7DD.16534801122009@news.aioe.org>

On 12/1/09 10:53 PM, John B. Matthews wrote:

> If I may amplify on this, the Java compiler rejects the assignment to
> its_color because it's a local variable, which must have an explicit
> value before use [1]. Once Tire's constructor completes, the value of
> spare.rim_color has the default value null [1]. The compiler need only
> check that its_color has been assigned in the current scope [2]. In
> Georg Bauhaus' example, the constructor is invoked in a nested scope.
>
> In Ada, I get a warning that '"Spare" is read but never assigned.'
>
> type Tire_Color is (Black, White);
> type Tire is record
>     Rim_Color : Tire_Color;
> end record;
> Spare : Tire;
>
> If I throw in "for Tire_Color use (Black =>  1, White =>  2)," the
> implicit initial value [3] of Rim_Color is not valid for Tire_Color.
> It's "a bounded error to evaluate the value of such an object [4]," and
> I get CONSTRAINT_ERROR at run-time.
>
> The Java compiler doesn't warn that spare.rim_color is null by default;
> the Ada compiler doesn't warn that Spare.Rim_Color is invalid by
> default. In either language, I have to either accept the default initial
> values or specify them. I sense I'm missing something.

The Java rule I had been thinking of starts from less emphasis
on what the default initial (Ada) value of a (local) variable
might be, given current Ada rules.  Rather, in the sequence
of statements below the compiler would just not accept the reference
to the .Rim_Color component of Spare.  The meaning of the
declaration Spare : Tire needs to be understood as slightly changed,
to exclude (or ignore) default initialization.

    Spare : Tire;
begin
    -- Here, whatever Spare is, or whichever side effects its
    -- declaration may have, it is not used between
    -- its declaration and the line following the if statement.
    -- Therefore, we are free to think of it as something
    -- or as nothing, or as something to become a Tire when
    -- necessary.  A virtual object, perhaps. (Otherwise, use
    -- syntax to indicate that  there is something important
    -- going on in default init; or, for compatibility, when
    -- nothing important is going on.)

    if Some_Condition then
       Spare := Make_a_Tire;
    end if;
    Its_Color := Spare.Rim_Color;  -- illegal


A simple rule would now be a copy of the Java rule which is
quoted below.  Just assume that Spare has no value.
Just like the last line is not accepted by SPARK or
by Java (the corresponding Java source line).  The warning
which some Ada compilers will issue (that Spare may not have
been assigned a value) is then turned into an error.
As might be expected in Ada, some syntax might be in
order to say that default initialization does
provide an initial value that warrants the safe use of the
variable after the if statement (or is needed for its
side effects, but this is another story, I guess).

Another case is when a declared variable is used in
a declaration of another variable following it,

    Spare   : Tire;
    Another : Tire := Spare;  -- might become illegal
begin
    ...

Illegal unless it is specified that Spare does have
a valid Tire value.  Or, oddly, that Another "inherits" the
unknown state of Spare WRT being initialized or not.

This is the Java rule I had in mind. I found it thanks to the
link you have supplied:
"A Java compiler must carry out a specific conservative flow
  analysis to make sure that, for every access of a local
  variable or blank final field f, f is definitely assigned
  before the access; otherwise a compile-time error must occur."


> [2]<http://java.sun.com/docs/books/jls/third_edition/html/defAssign.html#
> 25979>



  reply	other threads:[~2009-12-02  0:32 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-13 20:12 Operation can be dispatching in only one type xorque
2009-11-13 20:34 ` Dmitry A. Kazakov
2009-11-13 20:43   ` xorque
2009-11-13 21:14     ` Dmitry A. Kazakov
2009-11-13 20:44   ` xorque
2009-11-16 17:43 ` Adam Beneschan
2009-11-16 20:28   ` Dmitry A. Kazakov
2009-11-16 20:32     ` Dmitry A. Kazakov
2009-11-16 21:35     ` Adam Beneschan
2009-11-16 22:28       ` Dmitry A. Kazakov
2009-11-17 22:10         ` Adam Beneschan
2009-11-18  9:46           ` Dmitry A. Kazakov
2009-11-18 16:39             ` Adam Beneschan
2009-11-18 19:21               ` Dmitry A. Kazakov
2009-11-19  0:27                 ` Randy Brukardt
2009-11-19  2:11                   ` Robert A Duff
2009-11-19 15:57                     ` Adam Beneschan
2009-11-19 19:39                       ` Robert A Duff
2009-11-19 23:43                         ` Randy Brukardt
2009-11-19  8:50                   ` Dmitry A. Kazakov
2009-11-19 23:54                     ` Randy Brukardt
2009-11-20  8:34                       ` Dmitry A. Kazakov
2009-11-20 10:58                         ` Jean-Pierre Rosen
2009-11-21  6:02                         ` Randy Brukardt
2009-11-21 13:07                           ` Dmitry A. Kazakov
2009-11-22  5:45                         ` xorque
2009-11-22 11:25                           ` Georg Bauhaus
2009-11-22 11:30                             ` xorque
2009-11-22 16:25                             ` Dmitry A. Kazakov
2009-11-22 16:27                               ` xorque
2009-11-22 16:42                                 ` Dmitry A. Kazakov
2009-11-22 16:52                                   ` xorque
2009-11-22 17:41                                     ` Dmitry A. Kazakov
2009-11-22 18:03                                       ` xorque
2009-11-22 18:08                                         ` xorque
2009-11-22 18:28                                         ` Dmitry A. Kazakov
2009-11-22 18:41                                           ` xorque
2009-11-22 21:47                                           ` Robert A Duff
2009-11-23  3:42                                             ` stefan-lucks
2009-11-30 20:36                                               ` Robert A Duff
2009-11-30 23:54                                                 ` (see below)
2009-12-01 12:13                                                 ` Georg Bauhaus
2009-12-01 12:23                                                   ` Georg Bauhaus
2009-12-01 12:44                                                     ` Georg Bauhaus
2009-12-01 13:48                                                   ` Dmitry A. Kazakov
2009-12-01 15:02                                                     ` Georg Bauhaus
2009-12-01 16:18                                                       ` Dmitry A. Kazakov
2009-12-01 17:52                                                         ` Georg Bauhaus
2009-12-01 18:47                                                           ` Dmitry A. Kazakov
2009-12-01 21:53                                                             ` John B. Matthews
2009-12-02  0:32                                                               ` Georg Bauhaus [this message]
2009-12-02 11:18                                                                 ` John B. Matthews
2009-12-02 14:29                                                                   ` Jean-Pierre Rosen
2009-12-02 15:35                                                                     ` Georg Bauhaus
2009-12-02  1:13                                                             ` Georg Bauhaus
2009-12-02  9:07                                                               ` Dmitry A. Kazakov
2009-12-02 12:35                                                                 ` John B. Matthews
2009-12-02 13:35                                                                   ` Dmitry A. Kazakov
2009-12-03  5:23                                                                   ` Randy Brukardt
2009-12-03 20:21                                                                     ` John B. Matthews
2009-12-03  5:29                                                                 ` Randy Brukardt
2009-12-03 11:24                                                                   ` Georg Bauhaus
2009-12-03 23:08                                                                     ` Randy Brukardt
2009-12-04  8:52                                                                       ` Dmitry A. Kazakov
2009-12-05  2:45                                                                         ` Randy Brukardt
2009-12-05 10:32                                                                           ` Dmitry A. Kazakov
2009-12-08  0:19                                                                             ` Randy Brukardt
2009-12-08  4:30                                                                               ` stefan-lucks
2009-12-08  9:12                                                                                 ` Dmitry A. Kazakov
2009-12-10  4:09                                                                                   ` Randy Brukardt
2009-12-11  0:10                                                                                 ` Robert A Duff
2009-12-08  9:22                                                                               ` Dmitry A. Kazakov
2009-12-08 10:06                                                                                 ` Georg Bauhaus
2009-12-08 10:23                                                                                   ` Dmitry A. Kazakov
2009-12-08 10:33                                                                                     ` Georg Bauhaus
2009-12-08 10:49                                                                                       ` Dmitry A. Kazakov
2009-12-01 23:51                                                   ` Randy Brukardt
2009-11-23  8:52                                             ` Dmitry A. Kazakov
2009-11-30 20:43                                               ` Robert A Duff
2009-12-01  9:00                                                 ` Dmitry A. Kazakov
2009-12-01  5:45                                                   ` stefan-lucks
2009-12-01 11:12                                                     ` Dmitry A. Kazakov
2009-12-01  8:01                                                       ` stefan-lucks
2009-12-01 13:37                                                         ` Dmitry A. Kazakov
2009-12-15 23:54                                                         ` Robert A Duff
2009-11-23  7:48                                         ` Georg Bauhaus
2009-11-23  7:58                                           ` Georg Bauhaus
2009-11-19 16:04                 ` Adam Beneschan
2009-11-19  2:23           ` tmoran
2009-11-19  8:32             ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2015-11-23 10:23 operation " Serge Robyns
2015-11-23 11:29 ` Dmitry A. Kazakov
2015-11-23 13:05   ` Serge Robyns
2015-11-23 13:48     ` Dmitry A. Kazakov
2015-11-23 14:16       ` Serge Robyns
2015-11-23 14:59         ` G.B.
2015-11-23 15:52         ` Dmitry A. Kazakov
2015-11-23 17:40 ` Jeffrey R. Carter
2015-11-24  9:08   ` Serge Robyns
2015-11-24 16:44     ` AdaMagica
2015-11-24 17:09     ` Jeffrey R. Carter
2015-11-24 18:37       ` Serge Robyns
2015-11-24 20:18         ` Jeffrey R. Carter
2015-11-24 20:40           ` Serge Robyns
2015-11-24 20:25       ` Niklas Holsti
2015-11-24 21:48         ` Jeffrey R. Carter
2015-11-25  8:24           ` Dmitry A. Kazakov
2015-11-25 11:22             ` Serge Robyns
2015-11-25 17:38               ` Dmitry A. Kazakov
2015-11-26 11:30                 ` Serge Robyns
2015-11-26 13:14                   ` Dmitry A. Kazakov
2015-11-26 14:27                     ` Serge Robyns
2015-11-26 15:16                       ` J-P. Rosen
2015-11-26 18:27                         ` Serge Robyns
2015-11-26 21:20                           ` J-P. Rosen
2015-11-27  8:37                             ` Dmitry A. Kazakov
2015-11-27 12:58                               ` J-P. Rosen
2015-11-27 13:39                                 ` Dmitry A. Kazakov
2015-11-30 22:22                                   ` Randy Brukardt
2015-12-01  8:46                                     ` Dmitry A. Kazakov
2015-12-01 11:19                                       ` G.B.
2015-12-01 13:56                                         ` Dmitry A. Kazakov
2015-12-01 16:05                                           ` G.B.
2015-12-01 17:58                                             ` Dmitry A. Kazakov
2015-12-02 13:06                                               ` G.B.
2015-12-02 13:31                                                 ` Dmitry A. Kazakov
2015-12-02 19:33                                           ` Randy Brukardt
2015-12-02 19:27                                       ` Randy Brukardt
2015-11-29 17:59                     ` Jacob Sparre Andersen
2015-11-30 22:29                       ` Randy Brukardt
2015-11-25 12:27             ` G.B.
2015-11-25 17:25               ` Dmitry A. Kazakov
replies disabled

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