Add some tests related to instance variables

master
Leo White 2018-10-30 11:43:09 +00:00
parent 4af0a0026d
commit 27f621da75
2 changed files with 31 additions and 11 deletions

View File

@ -91,17 +91,6 @@ Error: This expression has type 'a * 'b
|}]
(** Masked instance variable *)
let c = object val x= 0 val y = x end
[%%expect{|
Line 1, characters 32-33:
1 | let c = object val x= 0 val y = x end
^
Error: The instance variable x
cannot be accessed from the definition of another instance variable
|}]
(** No value clause *)
let f x = match x with exception Not_found -> ();;

View File

@ -916,3 +916,34 @@ Line 2, characters 8-52:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This kind of recursive class expression is not allowed
|}];;
class a = object val x = 3 val y = x + 2 end;;
[%%expect{|
Line 1, characters 35-36:
1 | class a = object val x = 3 val y = x + 2 end;;
^
Error: The instance variable x
cannot be accessed from the definition of another instance variable
|}];;
class a = object (self) val x = self#m method m = 3 end;;
[%%expect{|
Line 1, characters 32-36:
1 | class a = object (self) val x = self#m method m = 3 end;;
^^^^
Error: The instance variable self
cannot be accessed from the definition of another instance variable
|}];;
class a = object method m = 3 end
class b = object inherit a as super val x = super#m end;;
[%%expect{|
class a : object method m : int end
Line 2, characters 44-49:
2 | class b = object inherit a as super val x = super#m end;;
^^^^^
Error: The instance variable super
cannot be accessed from the definition of another instance variable
|}];;