瀏覽代碼

[matcher] dodge capture var vs. abstract field regression

see #7728
Simon Krajewski 6 年之前
父節點
當前提交
50836fe225
共有 2 個文件被更改,包括 33 次插入0 次删除
  1. 11 0
      src/typing/matcher.ml
  2. 22 0
      tests/unit/src/unit/issues/Issue7728.hx

+ 11 - 0
src/typing/matcher.ml

@@ -250,12 +250,23 @@ module Pattern = struct
 				try_typing (EConst (Ident s),p)
 			with
 			| Exit | Bad_pattern _ ->
+				let restore =
+					let old = ctx.on_error in
+					ctx.on_error <- (fun _ _ _ ->
+						raise Exit
+					);
+					(fun () ->
+						ctx.on_error <- old
+					)
+				in
 				begin try
 					let mt = module_type_of_type t in
 					let e_mt = TyperBase.type_module_type ctx mt None p in
 					let e = type_field_access ctx ~resume:true e_mt s in
+					restore();
 					check_expr e
 				with _ ->
+					restore();
 					if not (is_lower_ident s) && (match s.[0] with '`' | '_' -> false | _ -> true) then begin
 						display_error ctx "Capture variables must be lower-case" p;
 					end;

+ 22 - 0
tests/unit/src/unit/issues/Issue7728.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+private enum E {
+	A(s:S);
+}
+
+private abstract S(String) {
+	public var value(get, never):String;
+	function get_value():String return this;
+}
+
+class Issue7728 extends unit.Test {
+	function test() {
+
+	}
+
+	static function doTest(e:E):Void {
+		switch(e) {
+			case A(value):
+		}
+	}
+}