瀏覽代碼

[typer] disallow accessing non-static abstract field statically (closes #5940)

Simon Krajewski 8 年之前
父節點
當前提交
4f15210171

+ 1 - 0
src/typing/typer.ml

@@ -1397,6 +1397,7 @@ and type_field ?(resume=false) ctx e i p mode =
 	| TAnon a ->
 		(try
 			let f = PMap.find i a.a_fields in
+			if Meta.has Meta.Impl f.cf_meta && not (Meta.has Meta.Enum f.cf_meta) then display_error ctx "Cannot access non-static abstract field statically" p;
 			if not f.cf_public && not ctx.untyped then begin
 				match !(a.a_status) with
 				| Closed | Extend _ -> () (* always allow anon private fields access *)

+ 10 - 0
tests/misc/projects/Issue5940/Main.hx

@@ -0,0 +1,10 @@
+class Main {
+    static function main() {
+        trace(Color.foo);
+    }
+}
+
+abstract Color(Int) {
+    public var foo(get, never):Int;
+    public function get_foo() return 0;
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:3: characters 15-24 : Cannot access non-static abstract field statically