caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* virtual instance variables
@ 2007-05-18 18:50 micha
  2007-05-21  6:04 ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 3+ messages in thread
From: micha @ 2007-05-18 18:50 UTC (permalink / raw)
  To: caml-list


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)

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?

cheers,
 Michael





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

* Re: [Caml-list] virtual instance variables
  2007-05-18 18:50 virtual instance variables micha
@ 2007-05-21  6:04 ` Jacques Garrigue
  0 siblings, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2007-05-21  6:04 UTC (permalink / raw)
  To: micha-1; +Cc: caml-list

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


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

* virtual instance variables
@ 2007-06-28 13:34 Jeremy Yallop
  0 siblings, 0 replies; 3+ messages in thread
From: Jeremy Yallop @ 2007-06-28 13:34 UTC (permalink / raw)
  To: Caml List

Should this be considered a bug?

    # (object val virtual c : float method m = c end) # m;;
    Segmentation fault


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

end of thread, other threads:[~2007-06-28 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-18 18:50 virtual instance variables micha
2007-05-21  6:04 ` [Caml-list] " Jacques Garrigue
2007-06-28 13:34 Jeremy Yallop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).