Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macro] Don't choke on namePos for reification pattern matching #11671

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/typing/matcher/exprToPattern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +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 && 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 ->
Expand Down
16 changes: 16 additions & 0 deletions tests/misc/projects/Issue11670/Main.hx
Original file line number Diff line number Diff line change
@@ -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 {};
}
}

1 change: 1 addition & 0 deletions tests/misc/projects/Issue11670/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-main Main
Empty file.
Loading