Browse Source

[matcher] don't let extractors access bindings (closes #6550)

Simon Krajewski 8 năm trước cách đây
mục cha
commit
6e941bff7c

+ 3 - 0
src/typing/matcher.ml

@@ -138,6 +138,7 @@ module Pattern = struct
 	type pattern_context = {
 		ctx : typer;
 		or_locals : (string, tvar * pos) PMap.t option;
+		ctx_locals : (string, tvar) PMap.t;
 		mutable current_locals : (string, tvar * pos) PMap.t;
 		mutable in_reification : bool;
 	}
@@ -437,6 +438,7 @@ module Pattern = struct
 					loop false e1
 			| EBinop(OpArrow,e1,e2) ->
 				let restore = save_locals ctx in
+				ctx.locals <- pctx.ctx_locals;
 				let v = add_local "_" null_pos in
 				let e1 = type_expr ctx e1 Value in
 				v.v_name <- "tmp";
@@ -458,6 +460,7 @@ module Pattern = struct
 		let pctx = {
 			ctx = ctx;
 			current_locals = PMap.empty;
+			ctx_locals = ctx.locals;
 			or_locals = None;
 			in_reification = false;
 		} in

+ 8 - 0
tests/misc/projects/Issue6550/Main.hx

@@ -0,0 +1,8 @@
+class Main {
+    static function main() {
+		switch [1, 2] {
+			case [var1, var1 == _ => true]:
+			case _:
+		}
+    }
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:4: characters 16-20 : Unknown identifier : var1