From 968bbffe5d4733a9f9e2fd4d193bc51f54c847f9 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 May 2024 11:19:11 +0200 Subject: [PATCH 1/3] [macro] Don't choke on namePos for reification pattern matching --- src/typing/matcher/exprToPattern.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/typing/matcher/exprToPattern.ml b/src/typing/matcher/exprToPattern.ml index 34a6ccd9ad1..843743b65a3 100644 --- a/src/typing/matcher/exprToPattern.ml +++ b/src/typing/matcher/exprToPattern.ml @@ -368,6 +368,7 @@ let rec make pctx toplevel t e = 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 && cf.cf_name = "namePos" 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 -> From e3b5e5b007125b3025eb9cf27bf4a4fd68358a7a Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 May 2024 11:19:25 +0200 Subject: [PATCH 2/3] [tests] Add test for 11670 --- tests/misc/projects/Issue11670/Main.hx | 16 ++++++++++++++++ tests/misc/projects/Issue11670/compile.hxml | 1 + .../misc/projects/Issue11670/compile.hxml.stdout | 0 3 files changed, 17 insertions(+) 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/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 From 9d726d0cd75e6795b0c962653deda1a391bafe58 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 May 2024 13:39:05 +0200 Subject: [PATCH 3/3] Do it like in #11433 --- src/typing/matcher/exprToPattern.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/typing/matcher/exprToPattern.ml b/src/typing/matcher/exprToPattern.ml index 843743b65a3..e3e897406d9 100644 --- a/src/typing/matcher/exprToPattern.ml +++ b/src/typing/matcher/exprToPattern.ml @@ -365,10 +365,14 @@ let rec make pctx toplevel t e = 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 && cf.cf_name = "namePos" 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 ->