Jelajahi Sumber

added php check on the full hierarchy for colliding names

Franco Ponticelli 17 tahun lalu
induk
melakukan
f1aa5ceea3
2 mengubah file dengan 13 tambahan dan 1 penghapusan
  1. 1 0
      doc/CHANGES.txt
  2. 12 1
      genphp.ml

+ 1 - 0
doc/CHANGES.txt

@@ -33,6 +33,7 @@ TODO inlining : substitute class+function type parameters in order to have fully
 	fixed hierarchy problem for classes with the name from different packages haXe/PHP
 	php.db.Mysql now throws an exception when tries to connect to an unexistant DB
 	fixed blocks in if statements for haXe/PHP
+	added php check on the full hierarchy for colliding names
 
 2008-07-28: 2.0
 	fixed current package bug in inherited constructor type

+ 12 - 1
genphp.ml

@@ -1624,6 +1624,17 @@ let generate_self_method ctx rights m static setter =
 	);
 	newline ctx
 
+let rec field_exists_in_hierarchy cl name =
+	if PMap.exists name cl.cl_fields then true
+	else (
+		match cl.cl_super with
+		| Some (c,_) -> 
+			field_exists_in_hierarchy c name
+		| None -> 
+			false
+	)
+	
+	
 let generate_field ctx static f =
 	newline ctx;
 	ctx.locals <- PMap.empty;
@@ -1632,7 +1643,7 @@ let generate_field ctx static f =
 	let p = ctx.curclass.cl_pos in
 	match f.cf_expr with
 	| Some { eexpr = TFunction fd } ->
-		if static && PMap.exists f.cf_name ctx.curclass.cl_fields then error ("Can't redeclare method (PHP limitation): " ^ f.cf_name) ctx.curclass.cl_pos;
+		if static && field_exists_in_hierarchy ctx.curclass f.cf_name then error ("Can't redeclare method (PHP limitation): " ^ f.cf_name) ctx.curclass.cl_pos;
 		spr ctx (rights ^ " ");
 		(match f.cf_set with
 		| NormalAccess when (match fd.tf_expr.eexpr with | TBlock _ -> true | _ -> false) ->