Pārlūkot izejas kodu

still allow matching on read-only extern static fields (closes #4679)

Simon Krajewski 9 gadi atpakaļ
vecāks
revīzija
ed113f4556

+ 2 - 0
matcher.ml

@@ -359,6 +359,8 @@ let to_pattern ctx e t =
 				mk_con_pat (CConst c) [] t p
 			| TTypeExpr mt ->
 				mk_type_pat ctx mt t p
+			| TField(_,FStatic({cl_extern = true},({cf_kind = Var {v_write = AccNever}} as cf))) ->
+				mk_con_pat (CExpr e) [] cf.cf_type p
 			| TField(_, FEnum(en,ef)) ->
 				begin try
 					unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_params) ef t

+ 32 - 0
tests/misc/projects/Issue4679/Main.hx

@@ -0,0 +1,32 @@
+extern class C {
+	static var PROXIMITY_BEGIN(default, never):String;
+	static var PROXIMITY_END(default, never):String;
+	static var PROXIMITY_MOVE(default, never):String;
+}
+
+@:native("C")
+@:keep
+class NotC {
+	static var PROXIMITY_BEGIN = "PROXIMITY_BEGIN";
+	static var PROXIMITY_END = "PROXIMITY_END";
+	static var PROXIMITY_MOVE = "PROXIMITY_MOVE";
+}
+
+class Main {
+	static function main() {
+		function print(s:Dynamic) {
+			Sys.stderr().writeString(s + "\n");
+		}
+		print(match(C.PROXIMITY_BEGIN));
+		print(match(C.PROXIMITY_END));
+		print(match(C.PROXIMITY_MOVE));
+	}
+
+	static function match(s:String) {
+		return switch (s) {
+			case C.PROXIMITY_BEGIN: 1;
+			case C.PROXIMITY_END: 2;
+			case _: 3;
+		}
+	}
+}

+ 2 - 0
tests/misc/projects/Issue4679/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+-x test

+ 3 - 0
tests/misc/projects/Issue4679/compile.hxml.stderr

@@ -0,0 +1,3 @@
+1
+2
+3