Răsfoiți Sursa

fixed incorrect method selection in inheritance chain

Nicolas Cannasse 9 ani în urmă
părinte
comite
6d692e96b1
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      genhl.ml

+ 6 - 1
genhl.ml

@@ -1371,7 +1371,12 @@ and get_access ctx e =
 			AStaticFun (alloc_fid ctx c f)
 		| FClosure (Some (cdef,pl), ({ cf_kind = Method m } as f)), TInst (c,_)
 		| FInstance (cdef,pl,({ cf_kind = Method m } as f)), TInst (c,_) when m <> MethDynamic && not (c.cl_interface || (is_overriden ctx c f && ethis.eexpr <> TConst(TSuper))) ->
-			AInstanceFun (ethis, alloc_fid ctx (resolve_class ctx cdef pl false) f)
+			(* cdef is the original definition, we want the last redefinition *)
+			let rec loop c =
+				if PMap.mem f.cf_name c.cl_fields then c else (match c.cl_super with None -> cdef | Some (c,_) -> loop c)
+			in
+			let last_def = loop c in
+			AInstanceFun (ethis, alloc_fid ctx (resolve_class ctx last_def pl false) f)
 		| (FInstance (cdef,pl,f) | FClosure (Some (cdef,pl), f)), _ ->
 			let cdef, pl = if cdef.cl_interface then (match follow ethis.etype with TInst (c,pl) -> c,pl | _ -> assert false) else cdef,pl in
 			object_access ctx ethis (class_type ctx cdef pl false) f