From b4695ee333ecd71bd6b6aa32a6bb811797a46380 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 22 Oct 2024 13:38:23 +0200 Subject: [PATCH] disallow `?.new` and `?.match` --- src/typing/typer.ml | 6 ++++-- tests/misc/projects/Issue11571/MainMatch.hx | 3 +++ tests/misc/projects/Issue11571/MainNew.hx | 3 +++ tests/misc/projects/Issue11571/compile-match-fail.hxml | 2 ++ .../misc/projects/Issue11571/compile-match-fail.hxml.stderr | 1 + tests/misc/projects/Issue11571/compile-new-fail.hxml | 2 ++ tests/misc/projects/Issue11571/compile-new-fail.hxml.stderr | 1 + 7 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/misc/projects/Issue11571/MainMatch.hx create mode 100644 tests/misc/projects/Issue11571/MainNew.hx create mode 100644 tests/misc/projects/Issue11571/compile-match-fail.hxml create mode 100644 tests/misc/projects/Issue11571/compile-match-fail.hxml.stderr create mode 100644 tests/misc/projects/Issue11571/compile-new-fail.hxml create mode 100644 tests/misc/projects/Issue11571/compile-new-fail.hxml.stderr diff --git a/src/typing/typer.ml b/src/typing/typer.ml index 5d5fa460541..52fc856b81f 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -629,7 +629,8 @@ and type_access ctx e p mode with_type = match e with | EConst (Ident s) -> type_ident ctx s p mode with_type - | EField (e1,"new",efk_todo) -> + | EField (e1,"new",efk) -> + if efk = EFSafe then raise_typing_error "?.new is not supported" p; let e1 = type_expr ctx e1 WithType.value in begin match e1.eexpr with | TTypeExpr (TClassDecl c) -> @@ -1752,7 +1753,8 @@ and type_call_builtin ctx e el mode with_type p = in warning ctx WInfo s e1.epos; e1 - | (EField(e,"match",efk_todo),p), [epat] -> + | (EField(e,"match",efk),p), [epat] -> + if efk = EFSafe then raise_typing_error "?.match is not supported" p; let et = type_expr ctx e WithType.value in let rec has_enum_match t = match follow t with | TEnum _ -> true diff --git a/tests/misc/projects/Issue11571/MainMatch.hx b/tests/misc/projects/Issue11571/MainMatch.hx new file mode 100644 index 00000000000..521ea0c0b24 --- /dev/null +++ b/tests/misc/projects/Issue11571/MainMatch.hx @@ -0,0 +1,3 @@ +function main() { + (macro 1).expr?.match(1); +} diff --git a/tests/misc/projects/Issue11571/MainNew.hx b/tests/misc/projects/Issue11571/MainNew.hx new file mode 100644 index 00000000000..cf5a89b2eaf --- /dev/null +++ b/tests/misc/projects/Issue11571/MainNew.hx @@ -0,0 +1,3 @@ +function main() { + String?.new; +} diff --git a/tests/misc/projects/Issue11571/compile-match-fail.hxml b/tests/misc/projects/Issue11571/compile-match-fail.hxml new file mode 100644 index 00000000000..7dddd28503f --- /dev/null +++ b/tests/misc/projects/Issue11571/compile-match-fail.hxml @@ -0,0 +1,2 @@ +--main MainMatch +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11571/compile-match-fail.hxml.stderr b/tests/misc/projects/Issue11571/compile-match-fail.hxml.stderr new file mode 100644 index 00000000000..995e1ef226d --- /dev/null +++ b/tests/misc/projects/Issue11571/compile-match-fail.hxml.stderr @@ -0,0 +1 @@ +MainMatch.hx:2: characters 2-23 : ?.match is not supported \ No newline at end of file diff --git a/tests/misc/projects/Issue11571/compile-new-fail.hxml b/tests/misc/projects/Issue11571/compile-new-fail.hxml new file mode 100644 index 00000000000..7b2c421d7b0 --- /dev/null +++ b/tests/misc/projects/Issue11571/compile-new-fail.hxml @@ -0,0 +1,2 @@ +--main MainNew +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11571/compile-new-fail.hxml.stderr b/tests/misc/projects/Issue11571/compile-new-fail.hxml.stderr new file mode 100644 index 00000000000..58da28c4cfc --- /dev/null +++ b/tests/misc/projects/Issue11571/compile-new-fail.hxml.stderr @@ -0,0 +1 @@ +MainNew.hx:2: characters 2-13 : ?.new is not supported \ No newline at end of file