فهرست منبع

[cs] More fixes from bugs introduced by abstracts casts

Cauê Waneck 10 سال پیش
والد
کامیت
18972f25c2
2فایلهای تغییر یافته به همراه13 افزوده شده و 9 حذف شده
  1. 12 8
      gencommon.ml
  2. 1 1
      std/cs/Pointer.hx

+ 12 - 8
gencommon.ml

@@ -6579,7 +6579,7 @@ struct
 			| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				is_abstract_to_struct (Abstract.get_underlying_type a pl)
 			| TInst(c,_) when Meta.has Meta.Struct c.cl_meta ->
-					true
+				true
 			| _ -> false
 		in
 
@@ -6772,13 +6772,17 @@ struct
 					| _ when is_abstract_to_struct expr.etype && type_iseq gen e.etype (get_abstract_impl expr.etype) ->
 						run { expr with etype = expr.etype }
 					| _ ->
-						let last_unsafe = gen.gon_unsafe_cast in
-						gen.gon_unsafe_cast <- (fun t t2 pos -> ());
-						let ret = handle (run expr) e.etype expr.etype in
-						gen.gon_unsafe_cast <- last_unsafe;
-						match ret.eexpr with
-							| TCast _ -> ret
-							| _ -> { e with eexpr = TCast(ret,md); etype = gen.greal_type e.etype }
+						match gen.greal_type e.etype, gen.greal_type expr.etype with
+							| (TInst(c,tl) as tinst1), TAbstract({ a_path = ["cs"],"Pointer" }, [tinst2]) when type_iseq gen tinst1 (gen.greal_type tinst2) ->
+								run expr
+							| _ ->
+								let last_unsafe = gen.gon_unsafe_cast in
+								gen.gon_unsafe_cast <- (fun t t2 pos -> ());
+								let ret = handle (run expr) e.etype expr.etype in
+								gen.gon_unsafe_cast <- last_unsafe;
+								match ret.eexpr with
+									| TCast _ -> { ret with etype = gen.greal_type e.etype }
+									| _ -> { e with eexpr = TCast(ret,md); etype = gen.greal_type e.etype }
 					)
 				(*| TCast _ ->
 					(* if there is already a cast, we should skip this cast check *)

+ 1 - 1
std/cs/Pointer.hx

@@ -43,7 +43,7 @@ import cs.StdTypes.Int64;
 #if !unsafe
 #error "You need to define 'unsafe' to be able to use unsafe code in hxcs"
 #else
-@:runtimeValue @:coreType abstract Pointer<T> from Int64
+@:runtimeValue @:coreType abstract Pointer<T> from Int64 from PointerAccess<T> to PointerAccess<T>
 {
 	@:op(A+B) public static function addIp<T>(lhs:Pointer<T>, rhs:Int):Pointer<T>;
 	@:op(A+B) public static function addp<T>(lhs:Pointer<T>, rhs:Int64):Pointer<T>;