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
spurious warning? "polymorphic method not principal"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-03-17 (08:17)
From: j h woodyatt <jhw@c...>
Subject: spurious warning? "polymorphic method not principal"

Please, consider the following test case:

> (* test.ml *)
> class alfa = object(_:'self)
>   method x: 'a. ('a, out_channel, unit) format -> 'a = Printf.printf
> end
> class bravo a = object
>   val y: alfa = (a :> alfa)
>   initializer y#x "bravo initialized"
> end
> class charlie a = object
>   inherit bravo a
>   initializer y#x "charlie initialized"
> end

$ ocamlc -principal -o test test.ml
File "test.ml", line 13, characters 14-17:
Warning X: this use of a polymorphic method is not principal.

It warns about the use of the polymorphic method on the object in the  
membership of the base class, but only when it's invoked from the  
derived class.  This confuses me.  Is this a bug in my code?   
(Perhaps, the word "principal" in this context doesn't mean what I  
think it means.)

Or is it a bug in the compiler?  If it isn't a bug in the compiler,  
could someone please explain to me why my program produced this  
warning?  Thank you very much.

j h woodyatt <jhw@conjury.org>