Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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:

> (* *)
> 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
File "", 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 <>