From e17d09974a2a1f6deb953a7438819eec2223e8f2 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 May 2024 14:29:20 +0200 Subject: [PATCH] [macro] Don't choke on namePos for reification pattern matching (#11671) * [macro] Don't choke on namePos for reification pattern matching * [tests] Add test for 11670 * Do it like in #11433 --- src/typing/matcher.ml | 7 ++++++- tests/misc/projects/Issue11670/Main.hx | 16 ++++++++++++++++ tests/misc/projects/Issue11670/compile.hxml | 1 + .../misc/projects/Issue11670/compile.hxml.stdout | 0 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/misc/projects/Issue11670/Main.hx create mode 100644 tests/misc/projects/Issue11670/compile.hxml create mode 100644 tests/misc/projects/Issue11670/compile.hxml.stdout diff --git a/src/typing/matcher.ml b/src/typing/matcher.ml index 450b619e1ba..f0d7cbe6f8b 100644 --- a/src/typing/matcher.ml +++ b/src/typing/matcher.ml @@ -480,9 +480,14 @@ module Pattern = struct let is_matchable cf = match cf.cf_kind with Method _ -> false | _ -> true in + (* TODO: This needs a better check, but it's not obvious how to approach this. See #11433 *) + let is_probably_pos cf = match cf.cf_name with + | "pos" | "posPath" | "namePos" -> true + | _ -> false + in let patterns,fields = List.fold_left (fun (patterns,fields) (cf,t) -> try - if pctx.in_reification && cf.cf_name = "pos" then raise Not_found; + if pctx.in_reification && is_probably_pos cf then raise Not_found; let e1 = Expr.field_assoc cf.cf_name fl in make pctx false t e1 :: patterns,cf.cf_name :: fields with Not_found -> diff --git a/tests/misc/projects/Issue11670/Main.hx b/tests/misc/projects/Issue11670/Main.hx new file mode 100644 index 00000000000..429ed1ca762 --- /dev/null +++ b/tests/misc/projects/Issue11670/Main.hx @@ -0,0 +1,16 @@ +class Main { + static function main() { + test(var foo:String); + } + + static macro function test(e) { + switch e { + // Unrecognized pattern: untyped $__mk_pos__("Test.hx", 145, 150) + case macro var $name:$ct: + case _: + } + + return macro {}; + } +} + diff --git a/tests/misc/projects/Issue11670/compile.hxml b/tests/misc/projects/Issue11670/compile.hxml new file mode 100644 index 00000000000..42409e72918 --- /dev/null +++ b/tests/misc/projects/Issue11670/compile.hxml @@ -0,0 +1 @@ +-main Main diff --git a/tests/misc/projects/Issue11670/compile.hxml.stdout b/tests/misc/projects/Issue11670/compile.hxml.stdout new file mode 100644 index 00000000000..e69de29bb2d