Browse Source

[display] don't check invalid assignments if we don't care

closes #9841
Simon Krajewski 4 years ago
parent
commit
c9712c6f6c
3 changed files with 29 additions and 2 deletions
  1. 1 1
      src/typing/callUnification.ml
  2. 1 1
      src/typing/operators.ml
  3. 27 0
      tests/display/src/cases/Issue9841.hx

+ 1 - 1
src/typing/callUnification.ml

@@ -378,7 +378,7 @@ class call_dispatcher
 	(p : pos)
 	(p : pos)
 =
 =
 	let is_set = match mode with MSet _ -> true | _ -> false in
 	let is_set = match mode with MSet _ -> true | _ -> false in
-	let check_assign () = if is_set then invalid_assign p in
+	let check_assign () = if is_set && ctx.com.display.dms_error_policy <> EPIgnore then invalid_assign p in
 
 
 object(self)
 object(self)
 
 

+ 1 - 1
src/typing/operators.ml

@@ -134,7 +134,7 @@ module BinopResult = struct
 end
 end
 
 
 let check_assign ctx e =
 let check_assign ctx e =
-	match e.eexpr with
+	if ctx.com.display.dms_error_policy <> EPIgnore then match e.eexpr with
 	| TLocal v when has_var_flag v VFinal ->
 	| TLocal v when has_var_flag v VFinal ->
 		error "Cannot assign to final" e.epos
 		error "Cannot assign to final" e.epos
 	| TLocal {v_extra = None} | TArray _ | TField _ | TIdent _ ->
 	| TLocal {v_extra = None} | TArray _ | TField _ | TIdent _ ->

+ 27 - 0
tests/display/src/cases/Issue9841.hx

@@ -0,0 +1,27 @@
+package cases;
+
+class Issue9841 extends DisplayTestCase {
+	/**
+		typedef Sprite = {
+			?x:Float,
+			?y:Float,
+			?scale:Float,
+		}
+
+		class Main {
+			static function main() {
+				addSprite(sprite -> {
+					sprite.{-1-} = 5;
+				});
+			}
+
+			static function addSprite(s:(sprite:Sprite) -> Void):Void {}
+		}
+	**/
+	function test() {
+		var fields = fields(pos(1));
+		eq(true, hasField(fields, "x", "Null<Float>", "var"));
+		eq(true, hasField(fields, "y", "Null<Float>", "var"));
+		eq(true, hasField(fields, "scale", "Null<Float>", "var"));
+	}
+}