Browse Source

don't allow variable redeclaration in subclasses.

Nicolas Cannasse 19 years ago
parent
commit
c4ed84a84e
1 changed files with 6 additions and 0 deletions
  1. 6 0
      typer.ml

+ 6 - 0
typer.ml

@@ -1861,10 +1861,16 @@ let init_class ctx c p herits fields =
 		| _ ->
 		| _ ->
 			load_type_opt ctx p t
 			load_type_opt ctx p t
 	in
 	in
+	let rec has_field f = function
+		| None -> false
+		| Some (c,_) ->
+			PMap.exists f c.cl_fields || has_field f c.cl_super || List.exists (fun i -> has_field f (Some i)) c.cl_implements
+	in
 	let loop_cf f p =
 	let loop_cf f p =
 		match f with
 		match f with
 		| FVar (name,doc,access,t,e) ->
 		| FVar (name,doc,access,t,e) ->
 			let stat = List.mem AStatic access in
 			let stat = List.mem AStatic access in
+			if not stat && has_field name c.cl_super then error ("Redefinition of variable " ^ name ^ " in subclass is not allowed") p;
 			let t = (match t with
 			let t = (match t with
 				| None ->
 				| None ->
 					if not stat then error ("Type required for member variable " ^ name) p;
 					if not stat then error ("Type required for member variable " ^ name) p;