From 9fc0dbbcf146c35860d3a17e1e2f5038d1c41402 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 30 Aug 2024 11:06:20 +0200 Subject: [PATCH 1/3] Don't lose monomorph when binding to Null See https://github.com/Simn/haxe/commit/02a7f9834b1327507eb9b6f646697960a0ec657f --- src/typing/typer.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typing/typer.ml b/src/typing/typer.ml index a2b74023129..d54c9a33677 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -401,7 +401,7 @@ let rec type_ident_raise ctx i p mode with_type = | TMono r when not (is_nullable t) -> (* If our expected type is a monomorph, bind it to Null. The is_nullable check is here because the expected type could already be Null, in which case we don't want to double-wrap (issue #11286). *) - Monomorph.do_bind r (tnull()) + Monomorph.bind r (tnull()) | _ -> (* Otherwise there's no need to create a monomorph, we can just type the null literal the way we expect it. *) From 2c3c38016af33786f489f4c54958e2692bf29109 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 30 Aug 2024 11:12:29 +0200 Subject: [PATCH 2/3] Add test --- tests/misc/projects/Issue11753/Main.hx | 31 ++++++++++++++++++ .../projects/Issue11753/compile-fail.hxml | 3 ++ .../Issue11753/compile-fail.hxml.stderr | 32 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/misc/projects/Issue11753/Main.hx create mode 100644 tests/misc/projects/Issue11753/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11753/compile-fail.hxml.stderr diff --git a/tests/misc/projects/Issue11753/Main.hx b/tests/misc/projects/Issue11753/Main.hx new file mode 100644 index 00000000000..18e0e373dd6 --- /dev/null +++ b/tests/misc/projects/Issue11753/Main.hx @@ -0,0 +1,31 @@ +class Main { + static var doThings : Foo -> Void; + + static function main() { + var foo = new Foo(); + doThings = (foo -> doThingsImpl(foo)); + doThings(foo); + } + + static function doThingsImpl(foo) { + foo.doWithBar(); + $type(foo); + $type(foo.doWithBar); + + if (foo != null) trace(foo); + $type(foo); + $type(foo.doWithBar); + } +} + +class Foo { + public function new() {} + public function doWithBar(?bar:Bar) { + trace(bar); + } +} + +@:keep +class Bar { + public function new() {} +} diff --git a/tests/misc/projects/Issue11753/compile-fail.hxml b/tests/misc/projects/Issue11753/compile-fail.hxml new file mode 100644 index 00000000000..740e71e491b --- /dev/null +++ b/tests/misc/projects/Issue11753/compile-fail.hxml @@ -0,0 +1,3 @@ +-main Main +--hl bin/main.hl +-D message.no-color diff --git a/tests/misc/projects/Issue11753/compile-fail.hxml.stderr b/tests/misc/projects/Issue11753/compile-fail.hxml.stderr new file mode 100644 index 00000000000..10671cc1f80 --- /dev/null +++ b/tests/misc/projects/Issue11753/compile-fail.hxml.stderr @@ -0,0 +1,32 @@ +[WARNING] Main.hx:12: characters 9-12 + + 12 | $type(foo); + | ^^^ + | Unknown<0> : { doWithBar : () -> Unknown<1> } + +[WARNING] Main.hx:13: characters 9-22 + + 13 | $type(foo.doWithBar); + | ^^^^^^^^^^^^^ + | () -> Unknown<0> + +[WARNING] Main.hx:16: characters 9-12 + + 16 | $type(foo); + | ^^^ + | Null<{ doWithBar : () -> Unknown<0> }> + +[WARNING] Main.hx:17: characters 9-22 + + 17 | $type(foo.doWithBar); + | ^^^^^^^^^^^^^ + | () -> Unknown<0> + +[ERROR] Main.hx:6: characters 35-38 + + 6 | doThings = (foo -> doThingsImpl(foo)); + | ^^^ + | error: (?bar : Null) -> Void should be () -> Unknown<0> + | have: { doWithBar: (?...) -> ... } + | want: { doWithBar: () -> ... } + From 3681d9efe4214c509f055c201ff4e3bc7595d3a9 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 30 Aug 2024 11:30:14 +0200 Subject: [PATCH 3/3] Whoops --- tests/misc/projects/Issue11753/compile-fail.hxml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/misc/projects/Issue11753/compile-fail.hxml b/tests/misc/projects/Issue11753/compile-fail.hxml index 740e71e491b..e3c103b20f6 100644 --- a/tests/misc/projects/Issue11753/compile-fail.hxml +++ b/tests/misc/projects/Issue11753/compile-fail.hxml @@ -1,3 +1,4 @@ -main Main --hl bin/main.hl +-D message.reporting=pretty -D message.no-color