English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
virtual instance variables
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-21 (06:04)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] virtual instance variables
From: micha <micha-1@fantasymail.de>

> entering in the toplevel: 
> class virtual c = object val virtual d : int end;;
> then:
> class d = object inherit c val d = 9 end;;
> gives me: Exception: Not_found.
> What is not found?  (compiling works)

Great, you found the first bug in this release!
To trigger it you must create a virtual instance variable without
using it (which is certainly useless, but allowed.)
This is now fixed in CVS.

Note that if you write 
  class virtual c = object val virtual d : int method d = d end;;
there is of course no problem.

> if I define:
>  class virtual c = object val d = 0 end;;
>  class d = object inherit c val d = 9 end;;
> gives the warning:
> Warning V: the instance variable d is overriden.
> The behaviour changed in ocaml 3.10 (previous behaviour was hiding.)
> I thought that  without the virtual declaration the behaviour is the
> same as before?

No, it is not. Or, more precisely, we reverted to the behviour of
ocaml 1. Visible instance variables are merged. To avoid this, you
must hide the first d by a coercion:

class d = object inherit (c : object end) val d = 9 end;;

Jacques Garrigue