浏览代码

[cs] Only cast physical fields when implementing the cast<T> function

Closes #6533
Caue Waneck 7 年之前
父节点
当前提交
55f3bbd878
共有 2 个文件被更改,包括 6 次插入35 次删除
  1. 6 2
      src/codegen/gencommon/realTypeParams.ml
  2. 0 33
      tests/unit/src/unit/issues/Issue6533.hx.disabled

+ 6 - 2
src/codegen/gencommon/realTypeParams.ml

@@ -201,15 +201,18 @@ let rec set_hxgeneric gen mds isfirst md =
 									let rec cfs_must_be_native cfs =
 										match cfs with
 											| [] -> false
-											| cf :: cfs ->
+											| cf :: cfs when Type.is_physical_field cf ->
 												let t = follow (gen.greal_type cf.cf_type) in
-												match t with
+												(match t with
 													| TInst( { cl_kind = KTypeParameter _ }, _ ) -> cfs_must_be_native cfs
 													| TInst(cl,p) when has_type_params t && is_false (set_hxgeneric gen mds isfirst (TClassDecl cl)) ->
 														if not (Hashtbl.mem gen.gtparam_cast cl.cl_path) then raise_or_return_true cf else cfs_must_be_native cfs
 													| TEnum(e,p) when has_type_params t && is_false (set_hxgeneric gen mds isfirst (TEnumDecl e)) ->
 														if not (Hashtbl.mem gen.gtparam_cast e.e_path) then raise_or_return_true cf else cfs_must_be_native cfs
 													| _ -> cfs_must_be_native cfs (* TAbstracts / Dynamics can't be generic *)
+												)
+											| _ :: cfs ->
+												cfs_must_be_native cfs
 									in
 									if cfs_must_be_native cl.cl_ordered_fields then begin
 										cl.cl_meta <- (Meta.NativeGeneric, [], cl.cl_pos) :: cl.cl_meta;
@@ -462,6 +465,7 @@ struct
 		let params = List.map snd cparams in
 
 		let fields = get_fields gen cl (List.map snd cl.cl_params) params [] in
+		let fields = List.filter (fun (cf,_,_) -> Type.is_physical_field cf) fields in
 
 		(* now create the contents of the function *)
 		(*

+ 0 - 33
tests/unit/src/unit/issues/Issue6533.hx.disabled

@@ -1,33 +0,0 @@
-package unit.issues;
-
-private interface InterfaceA<T> { }
-
-private abstract AbstractC<T>(ClassC<T>) {
-    public function new() this = new ClassC();
-}
-
-private class ClassC<T> implements InterfaceA<T> {
-
-    public var foo(get, never):Null<T>;
-    function get_foo():Null<T> return null;
-
-    public function new() { }
-}
-
-private interface EmptyGenericInterface<T> {
-}
-
-private class ClassWithNullableField<T> implements EmptyGenericInterface<T> {
-	public var nullableField:Null<T>;
-
-	public function new() {
-	}
-}
-
-class Issue6533 extends Test {
-    public function test():Void {
-        var example:ClassWithNullableField<Int> = new ClassWithNullableField<Int>();
-        example.nullableField = 42;
-        var c = new AbstractC();
-    }
-}