1 (***********************************************************************)
5 (* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1997 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
11 (***********************************************************************)
15 (* Inclusion checks for the class language *)
19 let class_types env cty1 cty2
=
20 Ctype.match_class_types env cty1 cty2
22 let class_type_declarations env cty1 cty2
=
23 Ctype.match_class_declarations env
24 cty1
.clty_params cty1
.clty_type
25 cty2
.clty_params cty2
.clty_type
27 let class_declarations env cty1 cty2
=
28 match cty1
.cty_new
, cty2
.cty_new
with
30 [Ctype.CM_Virtual_class
]
32 Ctype.match_class_declarations env
33 cty1
.cty_params cty1
.cty_type
34 cty2
.cty_params cty2
.cty_type
42 fprintf ppf
"A class cannot be changed from virtual to concrete"
43 | CM_Parameter_arity_mismatch
(ls
, lp
) ->
45 "The classes do not have the same number of type parameters"
46 | CM_Type_parameter_mismatch trace
->
48 (Printtyp.unification_error
false trace
50 fprintf ppf
"One type parameter has type"))
52 fprintf ppf
"but is expected to have type")
53 | CM_Class_type_mismatch
(cty1
, cty2
) ->
55 "@[The class type@;<1 2>%a@ is not matched by the class type@;<1 2>%a@]"
56 Printtyp.class_type cty1
Printtyp.class_type cty2
57 | CM_Parameter_mismatch trace
->
59 (Printtyp.unification_error
false trace
61 fprintf ppf
"One parameter has type"))
63 fprintf ppf
"but is expected to have type")
64 | CM_Val_type_mismatch
(lab
, trace
) ->
66 (Printtyp.unification_error
false trace
68 fprintf ppf
"The instance variable %s@ has type" lab
))
70 fprintf ppf
"but is expected to have type")
71 | CM_Meth_type_mismatch
(lab
, trace
) ->
73 (Printtyp.unification_error
false trace
75 fprintf ppf
"The method %s@ has type" lab
))
77 fprintf ppf
"but is expected to have type")
78 | CM_Non_mutable_value lab
->
80 "@[The non-mutable instance variable %s cannot become mutable@]" lab
81 | CM_Non_concrete_value lab
->
83 "@[The virtual instance variable %s cannot become concrete@]" lab
84 | CM_Missing_value lab
->
85 fprintf ppf
"@[The first class type has no instance variable %s@]" lab
86 | CM_Missing_method lab
->
87 fprintf ppf
"@[The first class type has no method %s@]" lab
88 | CM_Hide_public lab
->
89 fprintf ppf
"@[The public method %s cannot be hidden@]" lab
90 | CM_Hide_virtual
(k
, lab
) ->
91 fprintf ppf
"@[The virtual %s %s cannot be hidden@]" k lab
92 | CM_Public_method lab
->
93 fprintf ppf
"@[The public method %s cannot become private" lab
94 | CM_Virtual_method lab
->
95 fprintf ppf
"@[The virtual method %s cannot become concrete" lab
96 | CM_Private_method lab
->
97 fprintf ppf
"The private method %s cannot become public" lab
99 let report_error ppf
= function
102 let print_errs ppf errs
=
103 List.iter
(fun err
-> fprintf ppf
"@ %a" include_err err
) errs
in
104 fprintf ppf
"@[<v>%a%a@]" include_err err
print_errs errs