Forráskód Böngészése

improve error message on invalid static/non-static property accessor (closes #3726)

Simon Krajewski 10 éve
szülő
commit
d102f14dc2

+ 5 - 0
tests/misc/projects/Issue3726/Main1.hx

@@ -0,0 +1,5 @@
+class Main1 {
+    static var test(get, null):String;
+    function get_test() return "foo";
+    static function main():Void { }
+}

+ 5 - 0
tests/misc/projects/Issue3726/Main2.hx

@@ -0,0 +1,5 @@
+class Main2 {
+    var test(get, null):String;
+    static function get_test() return "foo";
+    static function main():Void { }
+}

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

@@ -0,0 +1 @@
+--run Main1

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

@@ -0,0 +1 @@
+Main1.hx:3: characters 4-36 : Method get_test is no valid accessor for test because it is not static

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

@@ -0,0 +1 @@
+--run Main2

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

@@ -0,0 +1 @@
+Main2.hx:3: characters 11-43 : Method get_test is no valid accessor for test because it is static

+ 7 - 1
typeload.ml

@@ -2177,7 +2177,13 @@ let init_class ctx c p context_init herits fields =
 							cf.cf_kind <- Method MethNormal;
 							cf.cf_kind <- Method MethNormal;
 							c.cl_fields <- PMap.add cf.cf_name cf c.cl_fields;
 							c.cl_fields <- PMap.add cf.cf_name cf c.cl_fields;
 							c.cl_ordered_fields <- cf :: c.cl_ordered_fields;
 							c.cl_ordered_fields <- cf :: c.cl_ordered_fields;
-						end else if not c.cl_extern then display_error ctx ("Method " ^ m ^ " required by property " ^ name ^ " is missing") p
+						end else if not c.cl_extern then begin
+							try
+								let _, _, f2 = (if not stat then let f = PMap.find m c.cl_statics in None, f.cf_type, f else class_field c (List.map snd c.cl_params) m) in
+								display_error ctx (Printf.sprintf "Method %s is no valid accessor for %s because it is %sstatic" m name (if stat then "not " else "")) f2.cf_pos
+							with Not_found ->
+								display_error ctx ("Method " ^ m ^ " required by property " ^ name ^ " is missing") p
+						end
 			in
 			in
 			let get = (match get with
 			let get = (match get with
 				| "null" -> AccNo
 				| "null" -> AccNo