Преглед на файлове

identifiers of local named functions are immutable (closes #7920)

Aleksandr Kuzmenko преди 6 години
родител
ревизия
99639ddb3f

+ 1 - 1
src/core/type.ml

@@ -420,7 +420,7 @@ let alloc_var =
 			v_type = t;
 			v_type = t;
 			v_id = !uid;
 			v_id = !uid;
 			v_capture = false;
 			v_capture = false;
-			v_final = false;
+			v_final = (match kind with VUser TVOLocalFunction -> true | _ -> false);
 			v_extra = None;
 			v_extra = None;
 			v_meta = [];
 			v_meta = [];
 			v_pos = p
 			v_pos = p

+ 2 - 0
src/typing/typer.ml

@@ -478,6 +478,8 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
 		let e2 with_type = type_expr ctx e2 with_type in
 		let e2 with_type = type_expr ctx e2 with_type in
 		(match e1 with
 		(match e1 with
 		| AKNo s -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
 		| AKNo s -> error ("Cannot access field or identifier " ^ s ^ " for writing") p
+		| AKExpr { eexpr = TLocal { v_kind = VUser TVOLocalFunction; v_name = name } } ->
+			error ("Cannot access function " ^ name ^ " for writing") p
 		| AKExpr e1  ->
 		| AKExpr e1  ->
 			let e2 = e2 (WithType.with_type e1.etype) in
 			let e2 = e2 (WithType.with_type e1.etype) in
 			let e2 = AbstractCast.cast_or_unify ctx e1.etype e2 p in
 			let e2 = AbstractCast.cast_or_unify ctx e1.etype e2 p in

+ 6 - 0
tests/misc/projects/Issue7920/Main.hx

@@ -0,0 +1,6 @@
+class Main {
+	public static function main() {
+		function local() {}
+		local = () -> trace('');
+	}
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:4: characters 3-26 : Cannot access function local for writing