浏览代码

[typer] bring back error on abstract member variable field

closes #9785
Simon Krajewski 5 年之前
父节点
当前提交
0279879866

+ 3 - 2
src/typing/typeloadFields.ml

@@ -954,7 +954,8 @@ module TypeBinding = struct
 end
 end
 
 
 let create_variable (ctx,cctx,fctx) c f t eo p =
 let create_variable (ctx,cctx,fctx) c f t eo p =
-	if not fctx.is_static && cctx.abstract <> None then error (fst f.cff_name ^ ": Cannot declare member variable in abstract") p;
+	let is_abstract_enum_field = Meta.has Meta.Enum f.cff_meta in
+	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 && 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;
 	if fctx.is_inline && eo = None then error (fst f.cff_name ^ ": Inline variable must be initialized") p;
 	if fctx.is_final && not (fctx.is_extern || (has_class_flag c CExtern) || (has_class_flag c CInterface))  && eo = None then begin
 	if fctx.is_final && not (fctx.is_extern || (has_class_flag c CExtern) || (has_class_flag c CInterface))  && eo = None then begin
@@ -988,7 +989,7 @@ let create_variable (ctx,cctx,fctx) c f t eo p =
 		cf.cf_meta <- ((Meta.Custom ":impl"),[],null_pos) :: cf.cf_meta;
 		cf.cf_meta <- ((Meta.Custom ":impl"),[],null_pos) :: cf.cf_meta;
 		add_class_field_flag cf CfImpl;
 		add_class_field_flag cf CfImpl;
 	end;
 	end;
-	if Meta.has Meta.Enum cf.cf_meta then add_class_field_flag cf CfEnum;
+	if is_abstract_enum_field then add_class_field_flag cf CfEnum;
 	ctx.curfield <- cf;
 	ctx.curfield <- cf;
 	TypeBinding.bind_var ctx cctx fctx cf eo;
 	TypeBinding.bind_var ctx cctx fctx cf eo;
 	cf
 	cf

+ 5 - 0
tests/misc/projects/Issue9785/Main.hx

@@ -0,0 +1,5 @@
+abstract Foo({}) {
+	public var x:Int;
+}
+
+function main() {}

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

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

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

@@ -0,0 +1 @@
+Main.hx:2: characters 2-19 : x: Cannot declare member variable in abstract