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

Do not raise final assign in display (#11200)

* Do not raise final assign in display

* handle `finalField|` hover case

* handle `finalField = value|` hover
RblSb 2 жил өмнө
parent
commit
e3f55b0a32

+ 4 - 1
src/typing/calls.ml

@@ -191,7 +191,10 @@ let rec acc_get ctx g =
 	in
 	let dispatcher p = new call_dispatcher ctx MGet WithType.value p in
 	match g with
-	| AKNo(_,p) -> typing_error ("This expression cannot be accessed for reading") p
+	| AKNo(acc,p) ->
+		if not (Common.ignore_error ctx.com) then
+			typing_error ("This expression cannot be accessed for reading") p
+		else acc_get ctx acc;
 	| AKExpr e -> e
 	| AKSafeNav sn ->
 		(* generate null-check branching for the safe navigation chain *)

+ 33 - 29
src/typing/operators.ml

@@ -570,35 +570,39 @@ let type_assign ctx e1 e2 with_type p =
 		| _ , _ -> ());
 		mk (TBinop (OpAssign,e1,e2)) e1.etype p
 	in
-	match e1 with
-	| AKNo(_,p) ->
-		typing_error "This expression cannot be accessed for writing" p
-	| AKUsingField _ | AKSafeNav _ ->
-		typing_error "Invalid operation" p
-	| AKExpr { eexpr = TLocal { v_kind = VUser TVOLocalFunction; v_name = name } } ->
-		typing_error ("Cannot access function " ^ name ^ " for writing") p
-	| AKField fa ->
-		let ef = FieldAccess.get_field_expr fa FWrite in
-		assign_to ef
-	| AKExpr e1  ->
-		assign_to e1
-	| AKAccessor fa ->
-		let dispatcher = new call_dispatcher ctx (MSet (Some e2)) with_type p in
-		dispatcher#accessor_call fa [] [e2]
-	| AKAccess(a,tl,c,ebase,ekey) ->
-		let e2 = type_rhs WithType.value in
-		mk_array_set_call ctx (AbstractCast.find_array_write_access ctx a tl ekey e2 p) c ebase p
-	| AKResolve(sea,name) ->
-		let eparam = sea.se_this in
-		let e_name = Texpr.Builder.make_string ctx.t name null_pos in
-		(new call_dispatcher ctx (MCall [e2]) with_type p)#field_call sea.se_access [eparam;e_name] [e2]
-	| AKUsingAccessor sea ->
-		let fa_set = match FieldAccess.resolve_accessor sea.se_access (MSet (Some e2)) with
-			| AccessorFound fa -> fa
-			| _ -> typing_error "Could not resolve accessor" p
-		in
-		let dispatcher = new call_dispatcher ctx (MCall [e2]) with_type p in
-		dispatcher#field_call fa_set [sea.se_this] [e2]
+	let rec check_acc e1 = match e1 with
+		| AKNo(acc,p) ->
+			if not (Common.ignore_error ctx.com) then
+				typing_error "This expression cannot be accessed for writing" p
+			else check_acc acc
+		| AKUsingField _ | AKSafeNav _ ->
+			typing_error "Invalid operation" p
+		| AKExpr { eexpr = TLocal { v_kind = VUser TVOLocalFunction; v_name = name } } ->
+			typing_error ("Cannot access function " ^ name ^ " for writing") p
+		| AKField fa ->
+			let ef = FieldAccess.get_field_expr fa FWrite in
+			assign_to ef
+		| AKExpr e1  ->
+			assign_to e1
+		| AKAccessor fa ->
+			let dispatcher = new call_dispatcher ctx (MSet (Some e2)) with_type p in
+			dispatcher#accessor_call fa [] [e2]
+		| AKAccess(a,tl,c,ebase,ekey) ->
+			let e2 = type_rhs WithType.value in
+			mk_array_set_call ctx (AbstractCast.find_array_write_access ctx a tl ekey e2 p) c ebase p
+		| AKResolve(sea,name) ->
+			let eparam = sea.se_this in
+			let e_name = Texpr.Builder.make_string ctx.t name null_pos in
+			(new call_dispatcher ctx (MCall [e2]) with_type p)#field_call sea.se_access [eparam;e_name] [e2]
+		| AKUsingAccessor sea ->
+			let fa_set = match FieldAccess.resolve_accessor sea.se_access (MSet (Some e2)) with
+				| AccessorFound fa -> fa
+				| _ -> typing_error "Could not resolve accessor" p
+			in
+			let dispatcher = new call_dispatcher ctx (MCall [e2]) with_type p in
+			dispatcher#field_call fa_set [sea.se_this] [e2]
+	in
+	check_acc e1
 
 let type_non_assign_op ctx op e1 e2 is_assign_op abstract_overload_only with_type p =
 	(* If the with_type is an abstract which has exactly one applicable @:op method, we can promote it

+ 48 - 0
tests/display/src/cases/Issue11173.hx

@@ -0,0 +1,48 @@
+package cases;
+
+class Foo {
+	public final field = 0;
+
+	public function new() {}
+}
+
+class Issue11173 extends DisplayTestCase {
+	/**
+		class Main {
+			static final {-1-}field{-2-} = 0;
+			static function main() {
+				{-3-}field{-4-} = 5;
+
+				final foo = new Foo();
+				foo.{-5-}field{-6-} = "ho${-9-}la";
+			}
+		}
+		class Foo {
+			public final {-7-}field{-8-} = "hi";
+			public function new() {}
+		}
+	**/
+	function test() {
+		arrayEq([
+			{
+				kind: DKCompilerError,
+				severity: Error,
+				range: diagnosticsRange(pos(3), pos(4)),
+				relatedInformation: [],
+				args: "This expression cannot be accessed for writing"
+			},
+			{
+				kind: DKCompilerError,
+				severity: Error,
+				range: diagnosticsRange(pos(5), pos(6)),
+				relatedInformation: [],
+				args: "This expression cannot be accessed for writing"
+			}
+		], diagnostics());
+		eq("Int", type(pos(4)));
+		eq("String", type(pos(6)));
+		eq(range(1, 2), position(pos(4)));
+		eq(range(7, 8), position(pos(6)));
+		eq("String", type(pos(9)));
+	}
+}