Browse Source

[matcher] properly error if Mark tries to capture tuples

closes #6965
Simon Krajewski 7 years ago
parent
commit
a9dd077299

+ 1 - 1
.vscode/tasks.json

@@ -6,7 +6,7 @@
 		{
 		{
 			"label": "Compile",
 			"label": "Compile",
 			"type": "shell",
 			"type": "shell",
-			"command": "make ADD_REVISION=1 -j -s haxe",
+			"command": "make ADD_REVISION=1 -f Makefile.win -j haxe",
 			"group": {
 			"group": {
 				"kind": "build",
 				"kind": "build",
 				"isDefault": true
 				"isDefault": true

+ 2 - 2
Makefile

@@ -147,14 +147,14 @@ build_pass_2:
 build_pass_3:
 build_pass_3:
 	ocamlfind ocamldep -slash $(OCAMLDEP_FLAGS) $(HAXE_INCLUDES) $(MODULES:%=%.ml) > Makefile.dependencies
 	ocamlfind ocamldep -slash $(OCAMLDEP_FLAGS) $(HAXE_INCLUDES) $(MODULES:%=%.ml) > Makefile.dependencies
 
 
-build_pass_4: $(MODULES:%=%.$(MODULE_EXT)) kill_exe_win
+build_pass_4: $(MODULES:%=%.$(MODULE_EXT))
 	$(COMPILER) -safe-string -linkpkg -g -o $(OUTPUT) $(NATIVE_LIBS) $(NATIVE_LIB_FLAG) $(LFLAGS) $(FINDLIB_PACKAGES) $(EXTLIB_INCLUDES) $(EXTLIB_LIBS:=.$(LIB_EXT)) $(MODULES:%=%.$(MODULE_EXT))
 	$(COMPILER) -safe-string -linkpkg -g -o $(OUTPUT) $(NATIVE_LIBS) $(NATIVE_LIB_FLAG) $(LFLAGS) $(FINDLIB_PACKAGES) $(EXTLIB_INCLUDES) $(EXTLIB_LIBS:=.$(LIB_EXT)) $(MODULES:%=%.$(MODULE_EXT))
 
 
 kill_exe_win:
 kill_exe_win:
 ifdef SYSTEMROOT
 ifdef SYSTEMROOT
 	-@taskkill /F /IM haxe.exe 2>/dev/null
 	-@taskkill /F /IM haxe.exe 2>/dev/null
 endif
 endif
-	
+
 plugin:
 plugin:
 ifeq ($(BYTECODE),1)
 ifeq ($(BYTECODE),1)
 	$(CC_CMD) $(PLUGIN).ml
 	$(CC_CMD) $(PLUGIN).ml

+ 6 - 9
src/typing/matcher.ml

@@ -299,16 +299,13 @@ module Pattern = struct
 				let ct = match e.eexpr with TConst ct -> ct | _ -> assert false in
 				let ct = match e.eexpr with TConst ct -> ct | _ -> assert false in
 				PatConstructor(ConConst ct,[])
 				PatConstructor(ConConst ct,[])
 			| EConst (Ident i) ->
 			| EConst (Ident i) ->
-				begin match i with
-					| "_" ->
-						begin match follow t with
-							| TFun(ta,tr) when tr == fake_tuple_type ->
-								PatTuple(List.map (fun (_,_,t) -> (PatAny,pos e)) ta)
-							| _ ->
-								PatAny
-						end
+				begin match follow t with
+					| TFun(ta,tr) when tr == fake_tuple_type ->
+						if i = "_" then PatTuple(List.map (fun (_,_,t) -> (PatAny,pos e)) ta)
+						else error "Cannot bind matched tuple to variable, use _ instead" p
 					| _ ->
 					| _ ->
-						handle_ident i (pos e)
+						if i = "_" then PatAny
+						else handle_ident i (pos e)
 				end
 				end
 			| EVars([(s,p),None,None]) ->
 			| EVars([(s,p),None,None]) ->
 				let v = add_local s p in
 				let v = add_local s p in

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

@@ -0,0 +1,8 @@
+class Main {
+    static function main() {
+        switch ["a", "b"] {
+            case [a = "something", "something"]:
+            case fallback:
+        }
+    }
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:5: characters 18-26 : Cannot bind matched tuple to variable, use _ instead