Browse Source

[typer] don't check names of things that have @:native

see #8742
Simon Krajewski 6 years ago
parent
commit
408f2dd140
3 changed files with 17 additions and 10 deletions
  1. 8 1
      src/typing/macroContext.ml
  2. 1 1
      src/typing/typeloadFields.ml
  3. 8 8
      src/typing/typeloadModule.ml

+ 8 - 1
src/typing/macroContext.ml

@@ -307,9 +307,16 @@ let make_macro_api ctx p =
 			let ttype = Typeload.load_instance mctx (cttype,p) false in
 			let f () = Interp.decode_type_def v in
 			let m, tdef, pos = safe_decode ctx v "TypeDefinition" ttype p f in
+			let has_native_meta = match tdef with
+				| EClass d -> Meta.has Meta.Native d.d_meta
+				| EEnum d -> Meta.has Meta.Native d.d_meta
+				| ETypedef d -> Meta.has Meta.Native d.d_meta
+				| EAbstract d -> Meta.has Meta.Native d.d_meta
+				| _ -> false
+			in
 			let add is_macro ctx =
 				let mdep = Option.map_default (fun s -> TypeloadModule.load_module ctx (parse_path s) pos) ctx.m.curmod mdep in
-				let mnew = TypeloadModule.type_module ctx m mdep.m_extra.m_file [tdef,pos] pos in
+				let mnew = TypeloadModule.type_module ctx ~dont_check_path:(has_native_meta) m mdep.m_extra.m_file [tdef,pos] pos in
 				mnew.m_extra.m_kind <- if is_macro then MMacro else MFake;
 				add_dependency mnew mdep;
 			in

+ 1 - 1
src/typing/typeloadFields.ml

@@ -1322,7 +1322,7 @@ let init_field (ctx,cctx,fctx) f =
 	let name = fst f.cff_name in
 	TypeloadCheck.check_global_metadata ctx f.cff_meta (fun m -> f.cff_meta <- m :: f.cff_meta) c.cl_module.m_path c.cl_path (Some name);
 	let p = f.cff_pos in
-	if not c.cl_extern then Typecore.check_field_name ctx name p;
+	if not c.cl_extern && not (Meta.has Meta.Native f.cff_meta) then Typecore.check_field_name ctx name p;
 	List.iter (fun acc ->
 		match (fst acc, f.cff_kind) with
 		| APublic, _ | APrivate, _ | AStatic, _ | AFinal, _ | AExtern, _ -> ()

+ 8 - 8
src/typing/typeloadModule.ml

@@ -196,9 +196,9 @@ let module_pass_1 ctx m tdecls loadp =
 	let pt = ref None in
 	let rec make_decl acc decl =
 		let p = snd decl in
-		let check_type_name type_name =
+		let check_type_name type_name meta =
 			let module_name = snd m.m_path in
-			if type_name <> module_name then Typecore.check_uppercase_identifier_name ctx type_name "type" p;
+			if type_name <> module_name && not (Meta.has Meta.Native meta) then Typecore.check_uppercase_identifier_name ctx type_name "type" p;
 		in
 		let acc = (match fst decl with
 		| EImport _ | EUsing _ ->
@@ -223,7 +223,7 @@ let module_pass_1 ctx m tdecls loadp =
 				| HFinal -> c.cl_final <- true
 				| _ -> ()
 			) d.d_flags;
-			if not c.cl_extern then check_type_name name;
+			if not c.cl_extern then check_type_name name d.d_meta;
 			decls := (TClassDecl c, decl) :: !decls;
 			acc
 		| EEnum d ->
@@ -247,12 +247,12 @@ let module_pass_1 ctx m tdecls loadp =
 				e_names = [];
 				e_type = enum_module_type m path p;
 			} in
-			if not e.e_extern then check_type_name name;
+			if not e.e_extern then check_type_name name d.d_meta;
 			decls := (TEnumDecl e, decl) :: !decls;
 			acc
 		| ETypedef d ->
 			let name = fst d.d_name in
-			check_type_name name;
+			check_type_name name d.d_meta;
 			if has_meta Meta.Using d.d_meta then error "@:using on typedef is not allowed" p;
 			pt := Some p;
 			let priv = List.mem EPrivate d.d_flags in
@@ -279,7 +279,7 @@ let module_pass_1 ctx m tdecls loadp =
 			acc
 		 | EAbstract d ->
 		 	let name = fst d.d_name in
-			check_type_name name;
+			check_type_name name d.d_meta;
 			let priv = List.mem AbPrivate d.d_flags in
 			let path = make_path name priv in
 			let a = {
@@ -935,12 +935,12 @@ let handle_import_hx ctx m decls p =
 (*
 	Creates a new module and types [tdecls] into it.
 *)
-let type_module ctx mpath file ?(is_extern=false) tdecls p =
+let type_module ctx mpath file ?(dont_check_path=false) ?(is_extern=false) tdecls p =
 	let m = make_module ctx mpath file p in
 	Hashtbl.add ctx.g.modules m.m_path m;
 	let tdecls = handle_import_hx ctx m tdecls p in
 	let ctx = type_types_into_module ctx m tdecls p in
-	if is_extern then m.m_extra.m_kind <- MExtern else Typecore.check_module_path ctx m.m_path p;
+	if is_extern then m.m_extra.m_kind <- MExtern else if not dont_check_path then Typecore.check_module_path ctx m.m_path p;
 	begin if ctx.is_display_file then match ctx.com.display.dms_kind with
 		| DMResolve s ->
 			DisplayPath.resolve_position_by_path ctx {tname = s; tpackage = []; tsub = None; tparams = []} p