From 9e712ce50cc2b85a09135c13f072b9ba4fc28003 Mon Sep 17 00:00:00 2001 From: Dan Korostelev Date: Tue, 18 Jul 2017 12:51:36 +0300 Subject: [PATCH] [js] consider statics of @:native("") classes when renaming local vars (closes #6448) --- src/optimization/filters.ml | 12 +++++++++++- tests/unit/src/unit/issues/Issue6448.hx | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/optimization/filters.ml b/src/optimization/filters.ml index 7e9a8584033..007622cd328 100644 --- a/src/optimization/filters.ml +++ b/src/optimization/filters.ml @@ -237,10 +237,20 @@ let collect_reserved_local_names com = match com.platform with | Js -> let h = ref StringMap.empty in + let add name = h := StringMap.add name true !h in List.iter (fun mt -> let tinfos = t_infos mt in let native_name = try fst (get_native_name tinfos.mt_meta) with Not_found -> Path.flat_path tinfos.mt_path in - h := StringMap.add native_name true !h + if native_name = "" then + match mt with + | TClassDecl c -> + List.iter (fun cf -> + let native_name = try fst (get_native_name cf.cf_meta) with Not_found -> cf.cf_name in + add native_name + ) c.cl_ordered_statics; + | _ -> () + else + add native_name ) com.types; !h | _ -> StringMap.empty diff --git a/tests/unit/src/unit/issues/Issue6448.hx b/tests/unit/src/unit/issues/Issue6448.hx index d6aab67eb7a..846b1578ed3 100644 --- a/tests/unit/src/unit/issues/Issue6448.hx +++ b/tests/unit/src/unit/issues/Issue6448.hx @@ -1,17 +1,30 @@ package unit.issues; -@:native("some") +@:native("some6448") private class C { public var v = true; public function new() {} } +@:native("") +private extern class Lib { + @:native("___hx_returnTrue") + static function returnTrue():Bool; + + static function __init__():Void { + untyped __js__("function ___hx_returnTrue() { return true; }"); + } +} + class Issue6448 extends unit.Test { #if js @:analyzer(no_local_dce) function test() { - var some = null; + var some6448 = null; t(new C().v); + + function ___hx_returnTrue() return false; + t(Lib.returnTrue()); } #end }