File: errors.ml

package info (click to toggle)
ocaml 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 44,372 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,419; asm: 5,462; makefile: 3,684; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (77 lines) | stat: -rw-r--r-- 2,474 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(* TEST
 expect;
*)

class type virtual ['a] c = object constraint 'a = [<`A of int & float] end
[%%expect {|
Line 1, characters 0-75:
1 | class type virtual ['a] c = object constraint 'a = [<`A of int & float] end
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The type of this class,
       "class virtual ['_a] c :
         object constraint '_a = [< `A of int & float ] as '_weak1 end",
       contains non-collapsible conjunctive types in constraints.
       Type "int" is not compatible with type "float"
|}]

class type ct = object
  method x : int
end

class c (y : 'a * float) : ct = object
  method x = y
end
[%%expect{|
class type ct = object method x : int end
Lines 5-7, characters 32-3:
5 | ................................object
6 |   method x = y
7 | end
Error: The class type object method x : 'a * float end
       is not matched by the class type ct
       The class type object method x : 'a * float end
       is not matched by the class type object method x : int end
       The method x has type "'a * float" but is expected to have type "int"
       Type "'a * float" is not compatible with type "int"
|}]

let foo = 42#m;;
[%%expect{|
Line 1, characters 10-12:
1 | let foo = 42#m;;
              ^^
Error: This expression is not an object; it has type "int"
|}]

let foo = object (self) method foo = self#bar end;;
[%%expect{|
Line 1, characters 37-41:
1 | let foo = object (self) method foo = self#bar end;;
                                         ^^^^
Error: This expression has no method "bar"
|}]

class empty = object end
class also_empty = object inherit! empty end
[%%expect{|
class empty : object  end
Line 2, characters 26-40:
2 | class also_empty = object inherit! empty end
                              ^^^^^^^^^^^^^^
Error: This inheritance does not override any methods or instance variables
       but is explicitly marked as overriding with "!".
|}]


class ['a] c = object val x : 'a list ref = ref [] end
class ['a] x = let r = ref [] in object val x : 'a list ref = r end
[%%expect{|
class ['a] c : object val x : 'a list ref end
Line 2, characters 0-67:
2 | class ['a] x = let r = ref [] in object val x : 'a list ref = r end
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The type of this class,
       "class ['_a] x : object val x : '_a list ref end",
       contains the non-generalizable type variable(s): "'_a".
       (see manual section 6.1.2)
|}]