Browse Source

restore checking assign ops for final vars modification (fixes #10325)

Aleksandr Kuzmenko 4 years ago
parent
commit
2c3cdf3c7a

+ 1 - 0
src/typing/operators.ml

@@ -680,6 +680,7 @@ let type_assign_op ctx op e1 e2 with_type p =
 		field_rhs_by_name op cf.cf_name ev (WithType.with_type cf.cf_type)
 	in
 	let assign vr e r_rhs =
+		check_assign ctx e;
 		let assign e_rhs =
 			let e_rhs = AbstractCast.cast_or_unify ctx e.etype e_rhs p in
 			match e_rhs.eexpr with

+ 7 - 0
tests/misc/projects/Issue10325/Main.hx

@@ -0,0 +1,7 @@
+class Main {
+	static function main() {
+		final a = 2 + Std.random(10);
+		a += 1;
+		trace(a);
+	}
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:4: characters 3-4 : Cannot assign to final