Pārlūkot izejas kodu

make sure gen_local does not shadow class fields (fixed issue #817)

Simon Krajewski 13 gadi atpakaļ
vecāks
revīzija
04aa631b21
1 mainītis faili ar 13 papildinājumiem un 13 dzēšanām
  1. 13 13
      typecore.ml

+ 13 - 13
typecore.ml

@@ -186,7 +186,7 @@ let gen_local ctx t =
 	(* ensure that our generated local does not mask an existing one *)
 	let rec loop n =
 		let nv = (if n = 0 then "_g" else "_g" ^ string_of_int n) in
-		if PMap.mem nv ctx.locals then
+		if (PMap.mem nv ctx.locals) || (PMap.mem nv ctx.curclass.cl_fields) then
 			loop (n+1)
 		else
 			nv
@@ -213,16 +213,16 @@ let mk_field name t p = {
 
 let fake_modules = Hashtbl.create 0
 let create_fake_module ctx file =
-	let file = Common.unique_full_path file in
-	let mdep = (try Hashtbl.find fake_modules file with Not_found ->
-		let mdep = {
-			m_id = alloc_mid();
-			m_path = (["$DEP"],file);
-			m_types = [];
-			m_extra = module_extra file (Common.get_signature ctx.com) (file_time file) MFake;
-		} in
-		Hashtbl.add fake_modules file mdep;
-		mdep
-	) in
-	Hashtbl.replace ctx.g.modules mdep.m_path mdep;
+	let file = Common.unique_full_path file in
+	let mdep = (try Hashtbl.find fake_modules file with Not_found ->
+		let mdep = {
+			m_id = alloc_mid();
+			m_path = (["$DEP"],file);
+			m_types = [];
+			m_extra = module_extra file (Common.get_signature ctx.com) (file_time file) MFake;
+		} in
+		Hashtbl.add fake_modules file mdep;
+		mdep
+	) in
+	Hashtbl.replace ctx.g.modules mdep.m_path mdep;
 	mdep