Browse Source

[php] fix "cannot implement previously implemented interface" (closes #6208)

Alexander Kuzmenko 8 years ago
parent
commit
d4305e3e01
3 changed files with 18 additions and 1 deletions
  1. 1 0
      extra/CHANGES.txt
  2. 16 1
      src/generators/genphp.ml
  3. 1 0
      src/generators/genphp7.ml

+ 1 - 0
extra/CHANGES.txt

@@ -18,6 +18,7 @@
 	php7: fix `@:enum abstract` generation  without `-dce full` (#6175)
 	php7: fix using enum constructor with arguments as a call argument (#6177)
 	php/php7: fixed accessing enum constructors on enum type stored to a variable (#6159)
+	php/php7: fix "cannot implement previously implemented interface" (#6208)
 	php: fix invoking functions stored in dynamic static vars (#6158)
 
 	Standard Library:

+ 16 - 1
src/generators/genphp.ml

@@ -2079,7 +2079,22 @@ let generate_class ctx c =
 	| Some (csup,_) ->
 		requires_constructor := false;
 		print ctx "extends %s " (s_path ctx csup.cl_path csup.cl_extern c.cl_pos));
-	let implements = ExtList.List.unique ~cmp:(fun a b -> (fst a).cl_path = (fst b).cl_path) c.cl_implements in
+	(* Do not add interfaces which are implemented through other interfaces inheritance *)
+	let unique = List.filter
+		(fun (iface, _) ->
+			not (List.exists
+				(fun (probably_descendant, _) ->
+					if probably_descendant == iface then
+						false
+					else
+						is_parent iface probably_descendant
+				)
+				c.cl_implements
+			)
+		)
+		c.cl_implements
+	in
+	let implements = ExtList.List.unique ~cmp:(fun a b -> (fst a).cl_path = (fst b).cl_path) unique in
 	(match implements with
 	| [] -> ()
 	| l ->

+ 1 - 0
src/generators/genphp7.ml

@@ -3246,6 +3246,7 @@ class class_builder ctx (cls:tclass) =
 					match iface with
 						| (i, params) -> writer#use_t (TInst (i, params))
 				in
+				(* Do not add interfaces which are implemented through other interfaces inheritance *)
 				let unique = List.filter
 					(fun (iface, _) ->
 						not (List.exists