|
@@ -147,6 +147,7 @@ module Pattern = struct
|
|
|
ctx_locals : (string, tvar) PMap.t;
|
|
|
mutable current_locals : (string, tvar * pos) PMap.t;
|
|
|
mutable in_reification : bool;
|
|
|
+ is_postfix_match : bool;
|
|
|
}
|
|
|
|
|
|
exception Bad_pattern of string
|
|
@@ -180,6 +181,7 @@ module Pattern = struct
|
|
|
in
|
|
|
let add_local final name p =
|
|
|
let is_wildcard_local = name = "_" in
|
|
|
+ if not is_wildcard_local && pctx.is_postfix_match then error "Capture variables are not allowed in .match patterns" p;
|
|
|
if not is_wildcard_local && PMap.mem name pctx.current_locals then error (Printf.sprintf "Variable %s is bound multiple times" name) p;
|
|
|
match pctx.or_locals with
|
|
|
| Some map when not is_wildcard_local ->
|
|
@@ -505,13 +507,14 @@ module Pattern = struct
|
|
|
let pat = loop e in
|
|
|
pat,p
|
|
|
|
|
|
- let make ctx t e =
|
|
|
+ let make ctx t e postfix_match =
|
|
|
let pctx = {
|
|
|
ctx = ctx;
|
|
|
current_locals = PMap.empty;
|
|
|
ctx_locals = ctx.locals;
|
|
|
or_locals = None;
|
|
|
in_reification = false;
|
|
|
+ is_postfix_match = postfix_match;
|
|
|
} in
|
|
|
make pctx true t e
|
|
|
end
|
|
@@ -525,7 +528,7 @@ module Case = struct
|
|
|
case_pos : pos;
|
|
|
}
|
|
|
|
|
|
- let make ctx t el eg eo_ast with_type p =
|
|
|
+ let make ctx t el eg eo_ast with_type postfix_match p =
|
|
|
let rec collapse_case el = match el with
|
|
|
| e :: [] ->
|
|
|
e
|
|
@@ -546,7 +549,7 @@ module Case = struct
|
|
|
) ctx.locals [] in
|
|
|
let old_ret = ctx.ret in
|
|
|
ctx.ret <- map ctx.ret;
|
|
|
- let pat = Pattern.make ctx (map t) e in
|
|
|
+ let pat = Pattern.make ctx (map t) e postfix_match in
|
|
|
unapply_type_parameters ctx.type_params monos;
|
|
|
let eg = match eg with
|
|
|
| None -> None
|
|
@@ -1489,7 +1492,7 @@ end
|
|
|
module Match = struct
|
|
|
open Typecore
|
|
|
|
|
|
- let match_expr ctx e cases def with_type p =
|
|
|
+ let match_expr ctx e cases def with_type postfix_match p =
|
|
|
let match_debug = Meta.has (Meta.Custom ":matchDebug") ctx.curfield.cf_meta in
|
|
|
let rec loop e = match fst e with
|
|
|
| EArrayDecl el when (match el with [(EFor _ | EWhile _),_] -> false | _ -> true) ->
|
|
@@ -1514,7 +1517,7 @@ module Match = struct
|
|
|
in
|
|
|
let cases = List.map (fun (el,eg,eo,p) ->
|
|
|
let p = match eo with Some e when p = null_pos -> pos e | _ -> p in
|
|
|
- let case,bindings,pat = Case.make ctx t el eg eo with_type p in
|
|
|
+ let case,bindings,pat = Case.make ctx t el eg eo with_type postfix_match p in
|
|
|
case,bindings,[pat]
|
|
|
) cases in
|
|
|
let infer_switch_type () =
|