Archived/OCaml Errors: Difference between revisions

From Xen
Jump to navigationJump to search
(Migrated)
 
m (Removed superfluous <nowiki></nowiki> tag pairs.)
Line 18: Line 18:
Unbound_value of Longident.t
Unbound_value of Longident.t


<pre><nowiki>
<pre>
# x;;
# x;;
Unbound value x
Unbound value x
</nowiki></pre>
</pre>


Unbound_constructor of Longident.t
Unbound_constructor of Longident.t


<pre><nowiki>
<pre>
# X;;
# X;;
Unbound constructor X
Unbound constructor X
</nowiki></pre>
</pre>


Unbound_label of Longident.t
Unbound_label of Longident.t
Line 34: Line 34:
Constructor_arity_mismatch of Longident.t * int * int
Constructor_arity_mismatch of Longident.t * int * int


<pre><nowiki>
<pre>
# type x = A of int;;
# type x = A of int;;
type x = A of int
type x = A of int
# A;;
# A;;
The constructor A expects 1 argument(s), but is here applied to 0 argument(s)
The constructor A expects 1 argument(s), but is here applied to 0 argument(s)
</nowiki></pre>
</pre>


Label_mismatch of Longident.t * (type_expr * type_expr) list
Label_mismatch of Longident.t * (type_expr * type_expr) list
Pattern_type_clash of (type_expr * type_expr) list
Pattern_type_clash of (type_expr * type_expr) list


<pre><nowiki>
<pre>
# let f x = match (x:int) with
# let f x = match (x:int) with
| true -> 1
| true -> 1
Line 50: Line 50:
This pattern matches values of type bool
This pattern matches values of type bool
but is here used to match values of type int
but is here used to match values of type int
</nowiki></pre>
</pre>


Multiply_bound_variable of string
Multiply_bound_variable of string
Line 56: Line 56:
Expr_type_clash of (type_expr * type_expr) list
Expr_type_clash of (type_expr * type_expr) list


<pre><nowiki>
<pre>
# true+1;;
# true+1;;
This expression has type bool but is here used with type int
This expression has type bool but is here used with type int
</nowiki></pre>
</pre>


Apply_non_function of type_expr
Apply_non_function of type_expr


<pre><nowiki>
<pre>
# let f x = 2 in
# let f x = 2 in
f 2 3;;
f 2 3;;
This function is applied to too many arguments, maybe you forgot a `;'
This function is applied to too many arguments, maybe you forgot a `;'
</nowiki></pre>
</pre>




<pre><nowiki>
<pre>
# let f = 2 in
# let f = 2 in
f 3;;
f 3;;
This expression is not a function, it cannot be applied
This expression is not a function, it cannot be applied
</nowiki></pre>
</pre>


Apply_wrong_label of label * type_expr
Apply_wrong_label of label * type_expr


<pre><nowiki>
<pre>
# let f ~x () = x+1 in
# let f ~x () = x+1 in
f ~y:3 ();;
f ~y:3 ();;
Expecting function has type x:int -> int
Expecting function has type x:int -> int
This argument cannot be applied with label ~y
This argument cannot be applied with label ~y
</nowiki></pre>
</pre>




<pre><nowiki>
<pre>
# let f ~x ~x = 3+x in
# let f ~x ~x = 3+x in
f 3;;
f 3;;
Expecting function has type x:'a -> x:int -> int
Expecting function has type x:'a -> x:int -> int
This argument cannot be applied without label
This argument cannot be applied without label
</nowiki></pre>
</pre>


Label_multiply_defined of Longident.t
Label_multiply_defined of Longident.t
Line 98: Line 98:
Incomplete_format of string
Incomplete_format of string


<pre><nowiki>
<pre>
# Printf.printf "%";;
# Printf.printf "%";;
Premature end of format string ``"%"''
Premature end of format string ``"%"''
</nowiki></pre>
</pre>


Bad_conversion of string * int * char
Bad_conversion of string * int * char
Undefined_method of type_expr * string
Undefined_method of type_expr * string


<pre><nowiki>
<pre>
# class c = object method m = 3 end;;
# class c = object method m = 3 end;;
class c : object method m : int end
class c : object method m : int end
Line 114: Line 114:
This expression has type c
This expression has type c
It has no method fred
It has no method fred
</nowiki></pre>
</pre>


Undefined_inherited_method of string
Undefined_inherited_method of string
Unbound_class of Longident.t
Unbound_class of Longident.t


<pre><nowiki>
<pre>
# let p = new fred;;
# let p = new fred;;
Unbound class fred
Unbound class fred
</nowiki></pre>
</pre>


Virtual_class of Longident.t
Virtual_class of Longident.t


<pre><nowiki>
<pre>
# class virtual c = object method virtual m : int end;;
# class virtual c = object method virtual m : int end;;
class virtual c : object method virtual m : int end
class virtual c : object method virtual m : int end
# let p = new c;;
# let p = new c;;
One cannot create instances of the virtual class c
One cannot create instances of the virtual class c
</nowiki></pre>
</pre>


Private_type of type_expr
Private_type of type_expr
Line 137: Line 137:
Unbound_instance_variable of string
Unbound_instance_variable of string


<pre><nowiki>
<pre>
# class c = object
# class c = object
method setx = x <- x + 3
method setx = x <- x + 3
end;;
end;;
Unbound instance variable x
Unbound instance variable x
</nowiki></pre>
</pre>


Instance_variable_not_mutable of string
Instance_variable_not_mutable of string


<pre><nowiki>
<pre>
# class c = object
# class c = object
val x = 3
val x = 3
Line 152: Line 152:
end;;
end;;
The instance variable x is not mutable
The instance variable x is not mutable
</nowiki></pre>
</pre>


Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list
Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list


<pre><nowiki>
<pre>
# class c = object
# class c = object
method f () = 4
method f () = 4
Line 169: Line 169:
Type c = < f : unit -> int > is not a subtype of type
Type c = < f : unit -> int > is not a subtype of type
d = < f : unit -> int; g : unit -> int >
d = < f : unit -> int; g : unit -> int >
</nowiki></pre>
</pre>


Outside_class
Outside_class
Line 183: Line 183:
Scoping_let_module of string * type_expr
Scoping_let_module of string * type_expr


<pre><nowiki>
<pre>
# let module M =
# let module M =
struct
struct
Line 192: Line 192:
This `let module' expression has type M.t
This `let module' expression has type M.t
In this type, the locally bound module name M escapes its scope
In this type, the locally bound module name M escapes its scope
</nowiki></pre>
</pre>


Masked_instance_variable of Longident.t
Masked_instance_variable of Longident.t
Line 215: Line 215:
Pattern_type_clash of type_expr
Pattern_type_clash of type_expr


<pre><nowiki>
<pre>
# type t = Jim;;
# type t = Jim;;
type t = Jim
type t = Jim
# class c = object (x : t) end;;
# class c = object (x : t) end;;
This pattern cannot match self: it only matches values of type t
This pattern cannot match self: it only matches values of type t
</nowiki></pre>
</pre>


Repeated_parameter
Repeated_parameter
Line 238: Line 238:
Virtual_class of bool * string list * string list
Virtual_class of bool * string list * string list


<pre><nowiki>
<pre>
# class c = object method virtual f : int end;;
# class c = object method virtual f : int end;;
This class should be virtual. The following methods are undefined : f
This class should be virtual. The following methods are undefined : f
</nowiki></pre>
</pre>


Parameter_arity_mismatch of Longident.t * int * int
Parameter_arity_mismatch of Longident.t * int * int
Line 255: Line 255:
Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure
Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure


<pre><nowiki>
<pre>
# class c = object method f x = true end;;
# class c = object method f x = true end;;
The method f has type 'a -> bool where 'a is unbound
The method f has type 'a -> bool where 'a is unbound
</nowiki></pre>
</pre>




<pre><nowiki>
<pre>
# class ['b] c (x : 'a) = object method f = x end;;
# class ['b] c (x : 'a) = object method f = x end;;
The method f has type 'b where 'b is unbound
The method f has type 'b where 'b is unbound
</nowiki></pre>
</pre>


Make_nongen_seltype of type_expr
Make_nongen_seltype of type_expr
Line 283: Line 283:
Duplicate_constructor of string
Duplicate_constructor of string


<pre><nowiki>
<pre>
# type t = Jim | Jim;;
# type t = Jim | Jim;;
Two constructors are named Jim
Two constructors are named Jim
</nowiki></pre>
</pre>


Too_many_constructors
Too_many_constructors
Line 316: Line 316:
Bad_variance of int * (bool * bool) * (bool * bool)
Bad_variance of int * (bool * bool) * (bool * bool)


<pre><nowiki>
<pre>
# module M = struct type -'a t end;;
# module M = struct type -'a t end;;
module M : sig type -'a t end
module M : sig type -'a t end
Line 322: Line 322:
In this definition, expected parameter variances are not satisfied.
In this definition, expected parameter variances are not satisfied.
The 1st type parameter was expected to be covariant, but it is contravariant# (* with over 10 type parameters *)
The 1st type parameter was expected to be covariant, but it is contravariant# (* with over 10 type parameters *)
</nowiki></pre>
</pre>




<pre><nowiki>
<pre>
module M = struct
module M = struct
type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, -'l) t
type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, -'l) t
Line 335: Line 335:
In this definition, expected parameter variances are not satisfied.
In this definition, expected parameter variances are not satisfied.
The 12th type parameter was expected to be covariant, but it is contravariant
The 12th type parameter was expected to be covariant, but it is contravariant
</nowiki></pre>
</pre>


Unavailable_type_constructor of Path.t
Unavailable_type_constructor of Path.t
Line 341: Line 341:
Bad_fixed_type of string
Bad_fixed_type of string


<pre><nowiki>
<pre>
# type t = private int;;
# type t = private int;;
This fixed type is not an object or variant
This fixed type is not an object or variant
</nowiki></pre>
</pre>




Line 382: Line 382:
Unbound_type_variable of string
Unbound_type_variable of string


<pre><nowiki>
<pre>
# type t = Jim of 'a;;
# type t = Jim of 'a;;
Unbound type parameter 'a
Unbound type parameter 'a
</nowiki></pre>
</pre>


Unbound_type_constructor of Longident.t
Unbound_type_constructor of Longident.t
Line 417: Line 417:
Invalid_variable_name of string
Invalid_variable_name of string


<pre><nowiki>
<pre>
# type t = '_a list;;
# type t = '_a list;;
The type variable name '_a is not allowed in programs
The type variable name '_a is not allowed in programs
</nowiki></pre>
</pre>


However, the compiler can use this kind of variables to specify the type of polymorphic variables which become monomorphic after their first usage (it is a bit tricky ...):
However, the compiler can use this kind of variables to specify the type of polymorphic variables which become monomorphic after their first usage (it is a bit tricky ...):


<pre><nowiki>
<pre>
# let f = List.sort compare;;
# let f = List.sort compare;;
val f : '_a list -> '_a list = <fun>
val f : '_a list -> '_a list = <fun>
Line 431: Line 431:
# f;;
# f;;
- : int list -> int list = <fun>
- : int list -> int list = <fun>
</nowiki></pre>
</pre>


Cannot_quantify of string * type_expr
Cannot_quantify of string * type_expr
Line 442: Line 442:
The type constructor t would escape its scope
The type constructor t would escape its scope


<pre><nowiki>
<pre>
# let x = ref [];;
# let x = ref [];;
val x : '_a list ref = {contents = []}
val x : '_a list ref = {contents = []}
Line 449: Line 449:
# x := [C];;
# x := [C];;
The type constructor t would escape its scope
The type constructor t would escape its scope
</nowiki></pre>
</pre>


The universal variable v would escape its scope
The universal variable v would escape its scope

Revision as of 21:54, 28 November 2011


OCaml Errors

This page provides code examples which cause various OCaml compiler errors. The filenames refer to the OCaml source files in which the errors are defined. The internal error type definitions are used to refer to the errors. Please add examples to the various issues listed here as you come across them.

typing/typecore.ml

Unbound_value of Longident.t

# x;;
Unbound value x

Unbound_constructor of Longident.t

# X;;
Unbound constructor X

Unbound_label of Longident.t Polymorphic_label of Longident.t Constructor_arity_mismatch of Longident.t * int * int

# type x = A of int;;
type x = A of int
# A;;
The constructor A expects 1 argument(s), but is here applied to 0 argument(s)

Label_mismatch of Longident.t * (type_expr * type_expr) list Pattern_type_clash of (type_expr * type_expr) list

# let f x = match (x:int) with
  | true -> 1
  | false -> 0;;
This pattern matches values of type bool
 but is here used to match values of type int

Multiply_bound_variable of string Orpat_vars of Ident.t Expr_type_clash of (type_expr * type_expr) list

# true+1;;
This expression has type bool but is here used with type int

Apply_non_function of type_expr

# let f x = 2 in
  f 2 3;;
This function is applied to too many arguments, maybe you forgot a `;'


# let f = 2 in
  f 3;;
This expression is not a function, it cannot be applied

Apply_wrong_label of label * type_expr

# let f ~x () = x+1 in
  f ~y:3 ();;
Expecting function has type x:int -> int
This argument cannot be applied with label ~y


# let f ~x ~x = 3+x in
  f 3;;
Expecting function has type x:'a -> x:int -> int
This argument cannot be applied without label

Label_multiply_defined of Longident.t Label_missing of string list Label_not_mutable of Longident.t Incomplete_format of string

# Printf.printf "%";;
Premature end of format string ``"%"''

Bad_conversion of string * int * char Undefined_method of type_expr * string

# class c = object method m = 3 end;;
class c : object method m : int end
# let p = new c;;
val p : c = <obj>
# p#fred;;
This expression has type c
It has no method fred

Undefined_inherited_method of string Unbound_class of Longident.t

# let p = new fred;;
Unbound class fred

Virtual_class of Longident.t

# class virtual c = object method virtual m : int end;;
class virtual c : object method virtual m : int end
# let p = new c;;
One cannot create instances of the virtual class c

Private_type of type_expr Private_label of Longident.t * type_expr Unbound_instance_variable of string

# class c = object
    method setx = x <- x + 3
  end;;
Unbound instance variable x

Instance_variable_not_mutable of string

# class c = object
    val x = 3
    method setx = x <- x + 3
  end;;
The instance variable x is not mutable

Not_subtype of (type_expr * type_expr) list * (type_expr * type_expr) list

# class c = object
    method f () = 4
  end;;
class c : object method f : unit -> int end
# class d = object 
    inherit c
    method g () = 3
  end;;
class d : object method f : unit -> int method g : unit -> int end
# let p = new c in (p : c :> d);;
Type c = < f : unit -> int > is not a subtype of type
  d = < f : unit -> int; g : unit -> int >

Outside_class

Value_multiply_overridden of string

Coercion_failure of type_expr * type_expr * (type_expr * type_expr) list * bool

Too_many_arguments of bool * type_expr

Abstract_wrong_label of label * type_expr

Scoping_let_module of string * type_expr

# let module M =
    struct
      type t = C
      let x = C
    end
  in M.x;;
This `let module' expression has type M.t
In this type, the locally bound module name M escapes its scope

Masked_instance_variable of Longident.t

Not_a_variant_type of Longident.t

Incoherent_label_order

Less_general of string * (type_expr * type_expr) list

typing/typeclass.ml

Unconsistent_constraint of (type_expr * type_expr) list

Field_type_mismatch of string * string * (type_expr * type_expr) list

Structure_expected of class_type

Cannot_apply of class_type

Apply_wrong_label of label

Pattern_type_clash of type_expr

# type t = Jim;;
type t = Jim
# class c = object (x : t) end;;
This pattern cannot match self: it only matches values of type t

Repeated_parameter

Unbound_class of Longident.t

Unbound_class_2 of Longident.t

Unbound_class_type of Longident.t

Unbound_class_type_2 of Longident.t

Abbrev_type_clash of type_expr * type_expr * type_expr

Constructor_type_mismatch of string * (type_expr * type_expr) list

Virtual_class of bool * string list * string list

# class c = object method virtual f : int end;;
This class should be virtual. The following methods are undefined : f

Parameter_arity_mismatch of Longident.t * int * int

Parameter_mismatch of (type_expr * type_expr) list

Bad_parameters of Ident.t * type_expr * type_expr

Class_match_failure of Ctype.class_match_failure list

Unbound_val of string

Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure

# class c = object method f x = true end;;
The method f has type 'a -> bool where 'a is unbound


# class ['b] c (x : 'a) = object method f = x end;;
The method f has type 'b where 'b is unbound

Make_nongen_seltype of type_expr

Non_generalizable_class of Ident.t * Types.class_declaration

Cannot_coerce_self of type_expr

Non_collapsable_conjunction of Ident.t * Types.class_declaration * (type_expr * type_expr) list

Final_self_clash of (type_expr * type_expr) list

Mutability_mismatch of string * mutable_flag

typing/typedecl.ml

Repeated_parameter

Duplicate_constructor of string

# type t = Jim | Jim;;
Two constructors are named Jim

Too_many_constructors

Duplicate_label of string

Recursive_abbrev of string

Definition_mismatch of type_expr

Constraint_failed of type_expr * type_expr

Unconsistent_constraint of (type_expr * type_expr) list

Type_clash of (type_expr * type_expr) list

Parameters_differ of Path.t * type_expr * type_expr

Null_arity_external

Missing_native_external

Unbound_type_var of type_expr * type_declaration

Unbound_exception of Longident.t

Not_an_exception of Longident.t

Bad_variance of int * (bool * bool) * (bool * bool)

# module M = struct type -'a t end;;
module M : sig type -'a t end
# module N = struct type +'a t = 'a M.t end;;
In this definition, expected parameter variances are not satisfied.
The 1st type parameter was expected to be covariant, but it is contravariant# (* with over 10 type parameters *)


  module M = struct
    type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, -'l) t
  end;;
module M : sig type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, -'l) t end
# module N = struct
    type ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, +'l) t = ('a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l) M.t
  end;;
In this definition, expected parameter variances are not satisfied.
The 12th type parameter was expected to be covariant, but it is contravariant

Unavailable_type_constructor of Path.t

Bad_fixed_type of string

# type t = private int;;
This fixed type is not an object or variant


typing/typemod.ml

Unbound_module of Longident.t

Unbound_modtype of Longident.t

Cannot_apply of module_type

Not_included of Includemod.error list

Cannot_eliminate_dependency of module_type

Signature_expected

Structure_expected of module_type

With_no_component of Longident.t

With_mismatch of Longident.t * Includemod.error list

Repeated_name of string * string

Non_generalizable of type_expr

Non_generalizable_class of Ident.t * class_declaration

Non_generalizable_module of module_type

Implementation_is_required of string

Interface_not_compiled of string

typing/typetexp.ml

Unbound_type_variable of string

# type t = Jim of 'a;;
Unbound type parameter 'a

Unbound_type_constructor of Longident.t

Unbound_type_constructor_2 of Path.t

Type_arity_mismatch of Longident.t * int * int

Bound_type_variable of string

Recursive_type

Unbound_class of Longident.t

Unbound_row_variable of Longident.t

Type_mismatch of (type_expr * type_expr) list

Alias_type_mismatch of (type_expr * type_expr) list

Present_has_conjunction of string

Present_has_no_type of string

Constructor_mismatch of type_expr * type_expr

Not_a_variant of type_expr

Variant_tags of string * string

Invalid_variable_name of string

# type t = '_a list;;
The type variable name '_a is not allowed in programs

However, the compiler can use this kind of variables to specify the type of polymorphic variables which become monomorphic after their first usage (it is a bit tricky ...):

# let f = List.sort compare;;
val f : '_a list -> '_a list = <fun>
# f [2;1;3];;
- : int list = [1; 2; 3]
# f;;
- : int list -> int list = <fun>

Cannot_quantify of string * type_expr

Unification error explanations

Errors relating to unification failure invoke the report_unification_error function from typing/printtyp.ml. In certain circumstances this function prints one of the following explanations.

Self type cannot escape its class

The type constructor t would escape its scope

# let x = ref [];;
val x : '_a list ref = {contents = []}
# type t = C;;
type t = C
# x := [C];;
The type constructor t would escape its scope

The universal variable v would escape its scope

Self type cannot be unified with a closed object type

Types for method m are incompatible

The first object type has no method m

The second object type has no method m

These two variant types have no intersection

The first variant type does not allow tag(s) t

The second variant type does not allow tag(s) t

Types for tag `t are incompatible