فهرست منبع

Merge branch 'development' into constrained_monomorphs

Simon Krajewski 6 سال پیش
والد
کامیت
e66f07ba25

+ 7 - 7
src-json/define.json

@@ -304,21 +304,21 @@
 	{
 		"name": "JsSourceMap",
 		"define": "js_source_map",
-		"doc": "Generate JavaScript source map even in non-debug mode.",
+		"doc": "Generate JavaScript source map even in non-debug mode. Deprecated in favor of `-D source_map`.",
 		"platforms": ["js"]
 	},
+	{
+		"name": "SourceMap",
+		"define": "source_map",
+		"doc": "Generate source map for compiled files. Note: for JavaScript prefer",
+		"platforms": ["php", "js"]
+	},
 	{
 		"name": "Jvm",
 		"define": "jvm",
 		"doc": "Generate jvm directly.",
 		"platforms": ["java"]
 	},
-	{
-		"name": "SourceMap",
-		"define": "source_map",
-		"doc": "Generate source map for compiled files.",
-		"platforms": ["php"]
-	},
 	{
 		"name": "KeepOldOutput",
 		"define": "keep_old_output",

+ 4 - 6
src/compiler/main.ml

@@ -667,13 +667,11 @@ let rec process_params create pl =
 				loop acc l
 			| _ -> loop (arg :: acc) l
 	in
-	(* put --display in each_params if it was last parameter *)
-	let pl = match List.rev pl with
-		| file :: "--display" :: pl when file <> "memory" ->
-			each_params := "--display" :: file :: !each_params;
-			List.rev pl
+	(* put --display in front if it was last parameter *)
+	let pl = (match List.rev pl with
+		| file :: "--display" :: pl when file <> "memory" -> "--display" :: file :: List.rev pl
 		| _ -> pl
-	in
+	) in
 	loop [] pl
 
 and init ctx =

+ 1 - 2
src/compiler/server.ml

@@ -52,8 +52,7 @@ let check_display_flush ctx f_otherwise = match ctx.com.json_out with
 			f_otherwise ()
 		end
 	| Some api ->
-		(* If there's a --next and we're in display mode, try that one. *)
-		if ctx.has_error && not (ctx.has_next && ctx.com.display.dms_display) then begin
+		if ctx.has_error then begin
 			let errors = List.map (fun msg ->
 				let msg,p,i = match msg with
 					| CMInfo(msg,p) -> msg,p,3

+ 7 - 2
src/generators/genpy.ml

@@ -2505,8 +2505,13 @@ module Generator = struct
 		if has_feature ctx "closure_Array" || has_feature ctx "closure_String" then
 			spr ctx "from functools import partial as _hx_partial\n";
 		spr ctx "import sys\n";
-		spr ctx "if sys.stdout.encoding != 'utf-8':\n    sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)\n";
-		spr ctx "if sys.stderr.encoding != 'utf-8':\n    sys.stderr = open(sys.stderr.fileno(), mode='w', encoding='utf8', buffering=1)\n\n";
+		spr ctx "try:\n";
+		spr ctx "    if sys.stdout.encoding != 'utf-8':\n";
+		spr ctx "        sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)\n";
+		spr ctx "    if sys.stderr.encoding != 'utf-8':\n";
+		spr ctx "        sys.stderr = open(sys.stderr.fileno(), mode='w', encoding='utf8', buffering=1)\n";
+		spr ctx "except:\n";
+		spr ctx "    pass\n";
 		gen_imports ctx;
 		gen_resources ctx;
 		gen_types ctx;

+ 2 - 2
src/optimization/inline.ml

@@ -520,8 +520,8 @@ class inline_state ctx ethis params cf f p = object(self)
 					add (mk (TVar (v,eo)) ctx.t.tvoid e.epos);
 				) vl;
 				List.iter (fun (l,e) -> match l.i_default_value with
-					| None -> ()
-					| Some e -> add (Texpr.set_default ctx.com.basic l.i_subst e e.epos)
+					| Some e when l.i_read > 0 -> add (Texpr.set_default ctx.com.basic l.i_subst e e.epos)
+					| _ -> ()
 				) _inlined_vars;
 				begin match e.eexpr with
 					| TBlock el -> List.iter add el

+ 9 - 5
src/typing/nullSafety.ml

@@ -430,16 +430,16 @@ let safety_mode (metadata:Ast.metadata) =
 		| Some mode -> mode
 		| None -> SMOff
 
-let rec validate_safety_meta error (metadata:Ast.metadata) =
+let rec validate_safety_meta report (metadata:Ast.metadata) =
 	match metadata with
 		| [] -> ()
 		| (Meta.NullSafety, args, pos) :: rest ->
 			(match args with
 				| ([] | [(EConst (Ident ("Off" | "Loose" | "Strict")), _)]) -> ()
-				| _ -> error "Invalid argument for @:nullSafety meta" pos
+				| _ -> add_error report "Invalid argument for @:nullSafety meta" pos
 			);
-			validate_safety_meta error rest
-		| _ :: rest -> validate_safety_meta error rest
+			validate_safety_meta report rest
+		| _ :: rest -> validate_safety_meta report rest
 
 (**
 	Check if specified `field` represents a `var` field which will exist at runtime.
@@ -1041,6 +1041,7 @@ class expr_checker mode immediate_execution report =
 				| TThrow expr -> self#check_throw expr e.epos
 				| TCast (expr, _) -> self#check_cast expr e.etype e.epos
 				| TMeta (m, _) when contains_unsafe_meta [m] -> ()
+				| TMeta ((Meta.NullSafety, _, _) as m, e) -> validate_safety_meta report [m]; self#check_expr e
 				| TMeta (_, e) -> self#check_expr e
 				| TEnumIndex idx -> self#check_enum_index idx e.epos
 				| TEnumParameter (e, _, _) -> self#check_expr e (** Checking enum value itself is not needed here because this expr always follows after TEnumIndex *)
@@ -1363,7 +1364,7 @@ class expr_checker mode immediate_execution report =
 				| _ -> ()
 	end
 
-class class_checker cls immediate_execution report  =
+class class_checker cls immediate_execution report =
 	let cls_meta = cls.cl_meta @ (match cls.cl_kind with KAbstractImpl a -> a.a_meta | _ -> []) in
 	object (self)
 			val is_safe_class = (safety_enabled cls_meta)
@@ -1373,9 +1374,11 @@ class class_checker cls immediate_execution report  =
 			Entry point for checking a class
 		*)
 		method check =
+			validate_safety_meta report cls_meta;
 			if is_safe_class && (not cls.cl_extern) && (not cls.cl_interface) then
 				self#check_var_fields;
 			let check_field is_static f =
+				validate_safety_meta report f.cf_meta;
 				match (safety_mode (cls_meta @ f.cf_meta)) with
 					| SMOff -> ()
 					| mode ->
@@ -1448,6 +1451,7 @@ class class_checker cls immediate_execution report  =
 		*)
 		method check_var_fields =
 			let check_field is_static field =
+				validate_safety_meta report field.cf_meta;
 				if should_be_initialized field then
 					if not (is_nullable_type field.cf_type) && self#is_in_safety field then
 						match field.cf_expr with

+ 7 - 1
src/typing/typer.ml

@@ -1014,7 +1014,13 @@ and type_binop2 ?(abstract_overload_only=false) ctx op (e1 : texpr) (e2 : Ast.ex
 			| [] ->
 				raise Not_found
 		in
-		loop a.a_ops
+		if left then
+			loop a.a_ops
+		else
+			let not_impl_or_is_commutative (_, cf) =
+				not (Meta.has Meta.Impl cf.cf_meta) || Meta.has Meta.Commutative cf.cf_meta
+			in
+			loop (List.filter not_impl_or_is_commutative a.a_ops)
 	in
 	try
 		begin match follow e1.etype with

+ 5 - 1
std/cs/io/NativeInput.hx

@@ -53,7 +53,11 @@ class NativeInput extends Input {
 	override public function readBytes(s:Bytes, pos:Int, len:Int):Int {
 		if (pos < 0 || len < 0 || pos + len > s.length)
 			throw Error.OutsideBounds;
-		var ret = stream.Read(s.getData(), pos, len);
+		var ret = 0;
+		var data = s.getData();
+		try {
+			ret = stream.Read(data, pos, len);
+		} catch (e: Dynamic) {}
 		if (ret == 0) {
 			_eof = true;
 			throw new Eof();

+ 18 - 0
tests/misc/projects/Issue8790/Main.hx

@@ -0,0 +1,18 @@
+class Main {
+	public static function main() {
+		1 + new Int8(1);
+	}
+}
+
+abstract Int8(Int) {
+
+	public inline function new(value:Int) {
+		this = value;
+	}
+
+	@:op(A + B) function addition(b:Int8):Int8;
+
+	@:op(A + B) static function intAddition(a:Int8, b:Int):Int {
+		return b + cast a;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue8790/compile-fail.hxml

@@ -0,0 +1 @@
+-main Main

+ 1 - 0
tests/misc/projects/Issue8790/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:3: characters 7-18 : Int8 should be Int

+ 3 - 1
tests/nullsafety/src/Validator.hx

@@ -23,7 +23,9 @@ class Validator {
 		for(field in Context.getBuildFields()) {
 			for(meta in field.meta) {
 				if(meta.name == ':shouldFail') {
-					expectedErrors.push({symbol: field.name, pos:field.pos});
+					var fieldPosInfos = Context.getPosInfos(field.pos);
+					fieldPosInfos.min = Context.getPosInfos(meta.pos).max + 1;
+					expectedErrors.push({symbol: field.name, pos:Context.makePosition(fieldPosInfos)});
 					break;
 				}
 			}

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

@@ -896,6 +896,9 @@ class TestStrict {
 		trace("hi", x);
 		trace("hi", shouldFail(x()));
 	}
+
+	@:shouldFail @:nullSafety(InvalidArgument)
+	static function invalidMetaArgument_shouldFail() {}
 }
 
 private class FinalNullableFields {

+ 12 - 0
tests/unit/src/unit/issues/Issue8791.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+class Issue8791 extends unit.Test {
+	function test() {
+		var a = write(true);
+		eq('', a);
+	}
+
+	static inline function write(binary = true) {
+		return '';
+	}
+}