Browse Source

disallow static constructor when class is typed (closes #2037)

Simon Krajewski 12 years ago
parent
commit
0af7ca3625
1 changed files with 7 additions and 5 deletions
  1. 7 5
      typeload.ml

+ 7 - 5
typeload.ml

@@ -1649,12 +1649,14 @@ let init_class ctx c p context_init herits fields =
 				name, c, t
 			) fd.f_args in
 			let t = TFun (fun_args args,ret) in
-			if constr && c.cl_interface then error "An interface cannot have a constructor" p;
 			if c.cl_interface && not stat && fd.f_expr <> None then error "An interface method cannot have a body" p;
-			if constr then (match fd.f_type with
-				| None | Some (CTPath { tpackage = []; tname = "Void" }) -> ()
-				| _ -> error "A class constructor can't have a return value" p
-			);
+			if constr then begin
+				if c.cl_interface then error "An interface cannot have a constructor" p;
+				if stat then error "A constructor must not be static" p;
+				match fd.f_type with
+					| None | Some (CTPath { tpackage = []; tname = "Void" }) -> ()
+					| _ -> error "A class constructor can't have a return value" p				
+			end; 
 			let cf = {
 				cf_name = name;
 				cf_doc = f.cff_doc;