Bläddra i källkod

fix error checking order for static final vars

Aleksandr Kuzmenko 5 år sedan
förälder
incheckning
cad98f7f5d

+ 9 - 4
src/typing/typeloadFields.ml

@@ -943,6 +943,13 @@ let create_variable (ctx,cctx,fctx) c f t eo p =
 	if fctx.is_abstract_member && not is_abstract_enum_field then error (fst f.cff_name ^ ": Cannot declare member variable in abstract") p;
 	if fctx.is_inline && not fctx.is_static then error (fst f.cff_name ^ ": Inline variable must be static") p;
 	if fctx.is_inline && eo = None then error (fst f.cff_name ^ ": Inline variable must be initialized") p;
+	let missing_initialization =
+		fctx.is_final
+		&& not (fctx.is_extern || (has_class_flag c CExtern) || (has_class_flag c CInterface))
+		&& eo = None
+	in
+	if missing_initialization && fctx.is_static && fctx.is_final then
+		error (fst f.cff_name ^ ": Static final variable must be initialized") p;
 	let t = (match t with
 		| None when eo = None ->
 			error ("Variable requires type-hint or initialization") (pos f.cff_name);
@@ -965,10 +972,8 @@ let create_variable (ctx,cctx,fctx) c f t eo p =
 		cf_kind = Var kind;
 	} in
 	if fctx.is_final then begin
-		if not (fctx.is_extern || (has_class_flag c CExtern) || (has_class_flag c CInterface))  && eo = None then begin
-			if fctx.is_static then error (fst f.cff_name ^ ": Static final variable must be initialized") p
-			else cctx.uninitialized_final <- cf :: cctx.uninitialized_final;
-		end;
+		if missing_initialization && not fctx.is_static then
+			cctx.uninitialized_final <- cf :: cctx.uninitialized_final;
 		add_class_field_flag cf CfFinal;
 	end;
 	if fctx.is_extern then add_class_field_flag cf CfExtern;

+ 1 - 1
tests/misc/projects/Issue6584/compile5-fail.hxml.stderr

@@ -1,2 +1,2 @@
 Main5.hx:1: lines 1-6 : This class has uninitialized final vars, which requires a constructor
-Main5.hx:2: characters 2-14 : Example of an uninitialized final var
+Main5.hx:2: characters 8-9 : Example of an uninitialized final var