Browse Source

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

ncannasse 6 years ago
parent
commit
8a2b8bc2b8

+ 5 - 5
src/macro/eval/evalStdLib.ml

@@ -973,12 +973,12 @@ module StdFile = struct
 
 	let write_out path content =
 		try
-	  		let ch = open_out_bin path in
-  			output_string ch content;
-  			close_out ch;
+			let ch = open_out_bin path in
+			output_string ch content;
+			close_out ch;
 			vnull
-		with Sys_error _ ->
-			exc_string ("Could not write file " ^ path)
+		with Sys_error s ->
+			exc_string s
 
 	let append = vfun2 (fun path binary ->
 		create_out path binary [Open_append]

+ 10 - 6
src/typing/nullSafety.ml

@@ -1417,7 +1417,7 @@ class class_checker cls immediate_execution report  =
 							| None -> Hashtbl.add fields_to_initialize f.cf_name f
 				)
 				cls.cl_ordered_fields;
-			let rec check_unsafe_usage init_list e =
+			let rec check_unsafe_usage init_list safety_enabled e =
 				if Hashtbl.length init_list > 0 then
 					match e.eexpr with
 						| TField ({ eexpr = TConst TThis }, FInstance (_, _, field)) ->
@@ -1427,13 +1427,17 @@ class class_checker cls immediate_execution report  =
 							checker#error ("Cannot use method " ^ field.cf_name ^ " until all instance fields are initialized.") [e.epos];
 						| TCall ({ eexpr = TField ({ eexpr = TConst TThis }, FInstance (_, _, field)) }, args) ->
 							checker#error ("Cannot call method " ^ field.cf_name ^ " until all instance fields are initialized.") [e.epos];
-							List.iter (check_unsafe_usage init_list) args
-						| TConst TThis ->
+							List.iter (check_unsafe_usage init_list safety_enabled) args
+						| TConst TThis when safety_enabled ->
 							checker#error "Cannot use \"this\" until all instance fields are initialized." [e.epos]
 						| TLocal v when Hashtbl.mem this_vars v.v_id ->
 							checker#error "Cannot use \"this\" until all instance fields are initialized." [e.epos]
+						| TMeta ((Meta.NullSafety, [(EConst (Ident "Off"), _)], _), e) ->
+							iter (check_unsafe_usage init_list false) e
+						| TMeta ((Meta.NullSafety, _, _), e) ->
+							iter (check_unsafe_usage init_list true) e
 						| _ ->
-							iter (check_unsafe_usage init_list) e
+							iter (check_unsafe_usage init_list safety_enabled) e
 			in
 			let rec traverse init_list e =
 				(match e.eexpr with
@@ -1441,7 +1445,7 @@ class class_checker cls immediate_execution report  =
 						Hashtbl.remove init_list f.cf_name;
 						ignore (traverse init_list right_expr)
 					| TWhile (condition, body, DoWhile) ->
-						check_unsafe_usage init_list condition;
+						check_unsafe_usage init_list true condition;
 						ignore (traverse init_list body)
 					| TBlock exprs ->
 						List.iter (fun e -> ignore (traverse init_list e)) exprs
@@ -1455,7 +1459,7 @@ class class_checker cls immediate_execution report  =
 					| TVar (v, Some { eexpr = TConst TThis }) ->
 						Hashtbl.add this_vars v.v_id v
 					| _ ->
-						check_unsafe_usage init_list e
+						check_unsafe_usage init_list true e
 				);
 				init_list
 			in

+ 1 - 1
std/haxe/CallStack.hx

@@ -210,7 +210,7 @@ class CallStack {
 			}
 			return stack;
 		#elseif cs
-			return makeStack(new cs.system.diagnostics.StackTrace(cs.internal.Exceptions.exception, true));
+			return cs.internal.Exceptions.exception == null ? [] : makeStack(new cs.system.diagnostics.StackTrace(cs.internal.Exceptions.exception, true));
 		#elseif python
 			var stack = [];
 			var exc = python.lib.Sys.exc_info();

+ 12 - 2
std/neko/_std/String.hx

@@ -71,7 +71,14 @@ import haxe.iterators.StringKeyValueIterator;
 
 	public function indexOf( str : String, ?startIndex : Int ) : Int {
 		untyped {
-			var p = try __dollar__sfind(this.__s,if( startIndex == null ) 0 else startIndex,str.__s) catch( e : Dynamic ) null;
+			var l = __dollar__ssize(this.__s);
+			if( startIndex == null || startIndex < -l )
+				startIndex = 0;
+			if( startIndex > l )
+				return -1;
+			if( __dollar__ssize(str.__s) == 0 )
+				return startIndex < 0 ? l + startIndex : startIndex;
+			var p = try __dollar__sfind(this.__s,startIndex,str.__s) catch( e : Dynamic ) null;
 			if( p == null )
 				return -1;
 			return p;
@@ -81,8 +88,11 @@ import haxe.iterators.StringKeyValueIterator;
 	public function lastIndexOf( str : String, ?startIndex : Int ) : Int {
 		untyped {
 			var last = -1;
+			var l = __dollar__ssize(this.__s);
 			if( startIndex == null )
-				startIndex = __dollar__ssize(this.__s);
+				startIndex = l;
+			if( __dollar__ssize(str.__s) == 0 )
+				return startIndex > l ? l : startIndex;
 			while( true ) {
 				var p = try __dollar__sfind(this.__s,last+1,str.__s) catch( e : Dynamic ) null;
 				if( p == null || p > startIndex )

+ 1 - 0
tests/nullsafety/src/cases/TestStrict.hx

@@ -146,6 +146,7 @@ class TestStrict {
 			initializedInAllBranchesOfConstructor = 'hello';
 		}
 		shouldFail(acceptThis(this));
+		@:nullSafety(Off) acceptThis(this);
 		var self = this;
 		shouldFail(acceptThis(self));
 		shouldFail(instanceMethod());

+ 2 - 2
tests/sys/run.hxml

@@ -7,7 +7,7 @@ compile.hxml
 --next
 -cmd echo Neko   && neko bin/neko/sys.n
 -cmd echo Python && python3 bin/python/sys.py
--cmd echo Cpp    && bin/cpp/Main-Debug
+-cmd echo Cpp    && bin/cpp/Main-debug
 -cmd echo CS     && mono bin/cs/bin/Main-Debug.exe
 -cmd echo Java   && java -jar bin/java/Main-Debug.jar
 -cmd echo Php    && php bin/php/Main/index.php
@@ -16,7 +16,7 @@ compile.hxml
 # --next
 # -cmd echo Neko   && neko bin\neko\sys.n
 # -cmd echo Python && python3 bin\python\sys.py
-# -cmd echo Cpp    && bin\cpp\Main-Debug.exe
+# -cmd echo Cpp    && bin\cpp\Main-debug.exe
 # -cmd echo CS     && bin\cs\bin\Main-Debug.exe
 # -cmd echo Java   && java -jar bin\java\Main-Debug.jar
 # -cmd echo Php    && php bin\php\Main\index.php

+ 2 - 0
tests/unit/src/unit/issues/Issue8075.hx

@@ -1,6 +1,7 @@
 package unit.issues;
 
 class Issue8075 extends unit.Test {
+#if !as3
 	function test() {
 		var expect = #if static 0 #else null #end;
 		var a = [];
@@ -9,4 +10,5 @@ class Issue8075 extends unit.Test {
 		a[2] = 2;
 		eq(expect, a[0]);
 	}
+#end
 }

+ 5 - 0
tests/unit/src/unitstd/String.unit.hx

@@ -72,6 +72,11 @@ s.indexOf("oo") == 1;
 s.indexOf("o", 1) == 1;
 s.indexOf("o", 2) == 2;
 s.indexOf("o", 3) == -1;
+//s.indexOf("", -10) == 0;
+//s.indexOf("", 7) == 7; // see #8117
+//s.indexOf("", 8) == -1; // see #8117
+s.indexOf("r", 7) == -1;
+s.indexOf("r", 8) == -1;
 
 // lastIndexOf
 var s = "foofoofoobarbar";

+ 9 - 9
tests/unit/src/unitstd/haxe/Utf8.unit.hx

@@ -44,13 +44,13 @@ haxe.Utf8.compare(haxe.Utf8.sub(str, 1, 0), "") == 0;
 // #if (neko || php || cpp || lua || macro)
 // TODO neko, cpp, macro
 #if php
-haxe.Utf8.validate("\xf0\xa9\xb8\xbd\xe3\x81\x82\xc3\xab\x61") == true;
-haxe.Utf8.validate("\xed\x9f\xbf") == true;
-haxe.Utf8.validate("\xee\x80\x80") == true;
-haxe.Utf8.validate("\xf4\x8f\xbf\xbf") == true;
-haxe.Utf8.validate("\xf0\xa9\xb8\xbd\xe3\x81\xc3\xab\x61") == false;
-haxe.Utf8.validate("\xc0\xaf") == false; // redundant sequence
-haxe.Utf8.validate("\xed\xa0\x80") == false; // surrogate byte sequence
-haxe.Utf8.validate("\xed\xbf\xbf") == false; // surrogate byte sequence
-haxe.Utf8.validate("\xf4\x90\x80\x80") == false; // U+110000
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("f0a9b8bde38182c3ab61").toString()) == true;
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("ed9fbf").toString()) == true;
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("ee8080").toString()) == true;
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("f48fbfbf").toString()) == true;
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("f0a9b8bde381c3ab61").toString()) == false;
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("c0af").toString()) == false; // redundant sequence
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("eda080").toString()) == false; // surrogate byte sequence
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("edbfbf").toString()) == false; // surrogate byte sequence
+haxe.Utf8.validate(haxe.io.Bytes.ofHex("f4908080").toString()) == false; // U+110000
 #end