Ver Fonte

[matcher] don't complain about wildcard locals in or-patterns

closes #8296
Simon Krajewski há 6 anos atrás
pai
commit
6eccc884fb

+ 1 - 1
src/typing/matcher.ml

@@ -449,7 +449,7 @@ module Pattern = struct
 				let pctx2 = {pctx with current_locals = PMap.empty; or_locals = Some (pctx1.current_locals)} in
 				let pat2 = make pctx2 toplevel t e2 in
 				PMap.iter (fun name (v,p) ->
-					if not (PMap.mem name pctx2.current_locals) then verror name p;
+					if not (PMap.mem name pctx2.current_locals) && name <> "_" then verror name p;
 					pctx.current_locals <- PMap.add name (v,p) pctx.current_locals
 				) pctx1.current_locals;
 				PatOr(pat1,pat2)

+ 9 - 0
tests/benchs/mandelbrot/compile-jvm.hxml

@@ -0,0 +1,9 @@
+--main Mandelbrot
+-java bin/jvm
+-D jvm
+
+--next
+--main Mandelbrot
+-java bin/jvm-anon
+-D anon_objects
+-D jvm

+ 20 - 0
tests/unit/src/unit/issues/Issue8296.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+import haxe.ds.Option;
+
+class Issue8296 extends unit.Test {
+	function test() {
+		var a = option();
+		var b = option();
+		var s = switch [a, b] {
+			case [Some(parse(_) => Some(_)), _] | [_, Some(_)]:
+				'foo';
+			case _:
+				'bar';
+		}
+		eq("foo", s);
+	}
+
+	static function option() return Some('1');
+	static function parse(v:String):Option<Int> return Some(1);
+}