2
0
Эх сурвалжийг харах

Merge branch 'development' of https://github.com/HaxeFoundation/haxe into development

Dan Korostelev 6 жил өмнө
parent
commit
d042097fe9

+ 16 - 2
src/generators/genhl.ml

@@ -352,6 +352,10 @@ let fake_tnull =
 		a_params = ["T",t_dynamic];
 	}
 
+let alloc_vid =
+	let vid = ref 0 in
+	(fun() -> incr vid; !vid)
+
 let rec to_type ?tref ctx t =
 	match t with
 	| TMono r ->
@@ -395,6 +399,7 @@ let rec to_type ?tref ctx t =
 			PMap.find a ctx.anons_cache
 		with Not_found ->
 			let vp = {
+				vid = alloc_vid();
 				vfields = [||];
 				vindex = PMap.empty;
 			} in
@@ -541,6 +546,7 @@ and class_type ?(tref=None) ctx c pl statics =
 		PMap.find key_path ctx.cached_types
 	with Not_found when c.cl_interface && not statics ->
 		let vp = {
+			vid = alloc_vid();
 			vfields = [||];
 			vindex = PMap.empty;
 		} in
@@ -2797,8 +2803,16 @@ and eval_expr ctx e =
 		);
 		r
 	| TEnumParameter (ec,f,index) ->
-		let r = alloc_tmp ctx (match to_type ctx ec.etype with HEnum e -> let _,_,args = e.efields.(f.ef_index) in args.(index) | _ -> assert false) in
-		op ctx (OEnumField (r,eval_expr ctx ec,f.ef_index,index));
+		let pt, is_single = (match to_type ctx ec.etype with
+			| HEnum e ->
+				let _,_,args = e.efields.(f.ef_index) in
+				args.(index), Array.length e.efields = 1
+			| _ -> assert false
+		) in
+		let er = eval_expr ctx ec in
+		if is_single then op ctx (ONullCheck er); (* #7560 *)
+		let r = alloc_tmp ctx pt in
+		op ctx (OEnumField (r,er,f.ef_index,index));
 		cast_to ctx r (to_type ctx e.etype) e.epos
 	| TContinue ->
 		before_break_continue ctx;

+ 3 - 3
src/generators/hl2c.ml

@@ -113,7 +113,7 @@ let s_comp = function
 	| CNeq -> "!="
 
 let core_types =
-	let vp = { vfields = [||]; vindex = PMap.empty } in
+	let vp = { vid = -1; vfields = [||]; vindex = PMap.empty } in
 	let ep = { ename = ""; eid = 0; eglobal = None; efields = [||] } in
 	[HVoid;HUI8;HUI16;HI32;HI64;HF32;HF64;HBool;HBytes;HDyn;HFun ([],HVoid);HObj null_proto;HArray;HType;HRef HVoid;HVirtual vp;HDynObj;HAbstract ("",0);HEnum ep;HNull HVoid;HMethod ([],HVoid);HStruct null_proto]
 
@@ -746,7 +746,7 @@ let generate_function ctx f =
 					sexpr "if( %s != %s && (!%s || !%s || %s) ) goto %s" (reg a) (reg b) (reg a) (reg b) pcompare (label d)
 				else
 					sexpr "if( %s && %s && %s ) goto %s" (reg a) (reg b) pcompare (label d)
-			| HDyn , _ | _, HDyn ->
+			| (HDyn | HFun _), _ | _, (HDyn | HFun _) ->
 				let inv = if op = CGt || op = CGte then "&& i != hl_invalid_comparison " else "" in
 				sexpr "{ int i = hl_dyn_compare((vdynamic*)%s,(vdynamic*)%s); if( i %s 0 %s) goto %s; }" (reg a) (reg b) (s_comp op) inv (label d)
 			| HObj oa, HObj _ ->
@@ -769,7 +769,7 @@ let generate_function ctx f =
 					sexpr "if( %s != %s && (!%s || !%s || !%s->value || !%s->value || %s->value != %s->value) ) goto %s" (reg a) (reg b) (reg a) (reg b) (reg a) (reg b) (reg a) (reg b) (label d)
 				else
 					assert false
-			| HEnum _, HEnum _ | HDynObj, HDynObj | HFun _, HFun _ | HAbstract _, HAbstract _ ->
+			| HEnum _, HEnum _ | HDynObj, HDynObj | HAbstract _, HAbstract _ ->
 				phys_compare()
 			| HVirtual _, HObj _->
 				if op = CEq then

+ 4 - 3
src/generators/hlcode.ml

@@ -50,8 +50,8 @@ type ttype =
 	| HStruct of class_proto
 
 and class_proto = {
-	pname : string;
 	pid : int;
+	pname : string;
 	mutable pclassglobal : int option;
 	mutable psuper : class_proto option;
 	mutable pvirtuals : int array;
@@ -65,20 +65,21 @@ and class_proto = {
 }
 
 and enum_proto = {
-	ename : string;
 	eid : int;
+	ename : string;
 	mutable eglobal : int option;
 	mutable efields : (string * string index * ttype array) array;
 }
 
 and field_proto = {
-	fname : string;
 	fid : int;
+	fname : string;
 	fmethod : functable index;
 	fvirtual : int option;
 }
 
 and virtual_proto = {
+	vid : int;
 	mutable vfields : (string * string index * ttype) array;
 	mutable vindex : (string, int) PMap.t;
 }

+ 2 - 1
src/generators/hlinterp.ml

@@ -2379,6 +2379,7 @@ let check code macros =
 			| OJEq (a,b,delta) | OJNotEq (a,b,delta) ->
 				(match rtype a, rtype b with
 				| (HObj _ | HVirtual _), (HObj _ | HVirtual _) -> ()
+				| (HDyn | HFun _), (HDyn | HFun _) -> ()
 				| ta, tb when safe_cast tb ta -> ()
 				| _ -> reg a (rtype b));
 				can_jump delta
@@ -2483,7 +2484,7 @@ let check code macros =
 			| OToVirtual (r,v) ->
 				(match rtype r with
 				| HVirtual _ -> ()
-				| _ -> reg r (HVirtual {vfields=[||];vindex=PMap.empty;}));
+				| _ -> reg r (HVirtual {vid=(-1);vfields=[||];vindex=PMap.empty;}));
 				(match rtype v with
 				| HObj _ | HDynObj | HDyn | HVirtual _ -> ()
 				| _ -> reg v HDynObj)

+ 6 - 7
std/hl/_std/String.hx

@@ -80,19 +80,18 @@ class String {
 	}
 
 	public function lastIndexOf( str : String, ?startIndex : Int ) : Int {
-		var last = 0;
 		var max = this.length;
 		if( startIndex != null ) {
 			max = startIndex + str.length;
 			if( max < 0 ) max = 0;
 			if( max > this.length ) max = this.length;
 		}
-		max <<= 1;
-		while( true ) {
-			var p = findChar(last, max, str.bytes, str.length << 1);
-			if( p < 0 )
-				return (last >> 1) - 1;
-			last = p + 2;
+		var pos = max - str.length;
+		var slen = str.length << 1;
+		while( pos >= 0 ) {
+			if( bytes.compare(pos << 1, str.bytes, 0, slen) == 0 )
+				return pos;
+			pos--;
 		}
 		return -1;
 	}

+ 11 - 0
tests/unit/src/unit/issues/Issue8299.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue8299 extends unit.Test {
+	function test() {
+		eq(-1, foo(1, 2));
+	}
+
+	static function foo<T:Int>(a:T, b:T):Int {
+		return a - b;
+	}
+}