浏览代码

[cs] skip CompilerGenerated classes when loading from .NET dlls (see #9293)

i'm not 100% sure if this is correct, because i don't fully understand the `ilclass.cattrs` structure, but it seems to work
Dan Korostelev 5 年之前
父节点
当前提交
acb41ebd8f
共有 1 个文件被更改,包括 9 次插入5 次删除
  1. 9 5
      src/codegen/dotnet.ml

+ 9 - 5
src/codegen/dotnet.ml

@@ -220,10 +220,8 @@ let ilpath_s = function
 let get_cls = function
 	| _,_,c -> c
 
-(* TODO: When possible on Haxe, use this to detect flag enums, and make an abstract with @:op() *)
-(* that behaves like an enum, and with an enum as its underlying type *)
-let enum_is_flag ilcls =
-	let check_flag name ns = name = "FlagsAttribute" && ns = ["System"] in
+let has_attr expected_name expected_ns ilcls =
+	let check_flag name ns = (name = expected_name && ns = expected_ns) in
 	List.exists (fun a ->
 		match a.ca_type with
 			| TypeRef r ->
@@ -246,6 +244,12 @@ let enum_is_flag ilcls =
 				false
 	) ilcls.cattrs
 
+(* TODO: When possible on Haxe, use this to detect flag enums, and make an abstract with @:op() *)
+(* that behaves like an enum, and with an enum as its underlying type *)
+let enum_is_flag = has_attr "FlagsAttribute" ["System"]
+
+let is_compiler_generated = has_attr "CompilerGeneratedAttribute" ["System"; "Runtime"; "CompilerServices"]
+
 let convert_ilenum ctx p ?(is_flag=false) ilcls =
 	let meta = ref [
 		Meta.Native, [EConst (String (ilpath_s ilcls.cpath,SDoubleQuotes) ), p], p;
@@ -1188,7 +1192,7 @@ class net_library com name file_path std = object(self)
 					let path = netpath_to_hx std ilpath in
 					build path
 				) cls.cnested
-			| Some cls ->
+			| Some cls when not (is_compiler_generated cls) ->
 				let ctx = self#get_ctx in
 				let hxcls = convert_ilclass ctx p cls in
 				cp := (hxcls,p) :: !cp;