Sfoglia il codice sorgente

[typer] don't generate implicit abstract methods for non-methods

closes #10729
Simon Krajewski 3 anni fa
parent
commit
d442e50606

+ 9 - 5
src/typing/typeloadCheck.ml

@@ -366,6 +366,10 @@ module Inheritance = struct
 				end;
 				cf
 			in
+			let is_method () = match f.cf_kind with
+				| Method _ -> true
+				| Var _ -> false
+			in
 			try
 				let map2, t2, f2 = class_field_no_interf c f.cf_name in
 				let t2, f2 =
@@ -399,16 +403,16 @@ module Inheritance = struct
 								display_error ctx.com (compl_msg (error_msg (Unify l))) p;
 							end
 				)
-			with
-				| Not_found when (has_class_flag c CAbstract) ->
+			with Not_found ->
+				if (has_class_flag c CAbstract) && is_method() then begin
 					let cf = make_implicit_field () in
 					add_class_field_flag cf CfAbstract;
-				| Not_found when has_class_field_flag f CfDefault ->
+				end else if has_class_field_flag f CfDefault then begin
 					let cf = make_implicit_field () in
 					cf.cf_expr <- None;
 					add_class_field_flag cf CfExtern;
 					add_class_field_flag cf CfOverride;
-				| Not_found when not (has_class_flag c CInterface) ->
+				end else if not (has_class_flag c CInterface) then begin
 					if Diagnostics.error_in_diagnostics_run ctx.com c.cl_pos then
 						DynArray.add missing (f,t)
 					else begin
@@ -421,7 +425,7 @@ module Inheritance = struct
 						in
 						display_error ctx.com msg p
 					end
-				| Not_found -> ()
+				end
 		in
 		let check_field _ cf =
 			check_field cf;

+ 15 - 0
tests/misc/projects/Issue10729/Main.hx

@@ -0,0 +1,15 @@
+interface IA {
+	public var a:String;
+}
+
+abstract class A implements IA {
+	public function new() {}
+}
+
+class B extends A {
+	public function new() {
+		super();
+	}
+}
+
+function main() {}

+ 2 - 0
tests/misc/projects/Issue10729/compile-fail.hxml

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

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

@@ -0,0 +1 @@
+Main.hx:5: characters 16-17 : Field a needed by IA is missing