Browse Source

still allow `@:enum` var fields (closes #4867)

Simon Krajewski 9 năm trước cách đây
mục cha
commit
3d8d06a7e1
2 tập tin đã thay đổi với 22 bổ sung1 xóa
  1. 21 0
      tests/unit/src/unit/issues/Issue4867.hx
  2. 1 1
      typer.ml

+ 21 - 0
tests/unit/src/unit/issues/Issue4867.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+@:enum
+private abstract EnumAbstract(Int) to Int {
+    var a = 0;
+    var b = 1;
+
+    @:from
+    public static function fromString(s:String):EnumAbstract {
+        if (s == "b")
+            return b;
+        return a;
+    }
+}
+
+class Issue4867 extends Test {
+	function test() {
+		var b:EnumAbstract = "b";
+		eq(1, b);
+	}
+}

+ 1 - 1
typer.ml

@@ -1362,7 +1362,7 @@ let rec type_ident_raise ctx i p mode =
 	with Not_found -> try
 		(* static variable lookup *)
 		let f = PMap.find i ctx.curclass.cl_statics in
-		if Meta.has Meta.Impl f.cf_meta && not (Meta.has Meta.Impl ctx.curfield.cf_meta) then
+		if Meta.has Meta.Impl f.cf_meta && not (Meta.has Meta.Impl ctx.curfield.cf_meta) && not (Meta.has Meta.Enum f.cf_meta) then
 			error (Printf.sprintf "Cannot access non-static field %s from static method" f.cf_name) p;
 		let e = type_type ctx ctx.curclass.cl_path p in
 		(* check_locals_masking already done in type_type *)