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

[typer] Monomorph vs Null<T> inference #11753

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down
31 changes: 31 additions & 0 deletions tests/misc/projects/Issue11753/Main.hx
Original file line number Diff line number Diff line change
@@ -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() {}
}
4 changes: 4 additions & 0 deletions tests/misc/projects/Issue11753/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-main Main
--hl bin/main.hl
-D message.reporting=pretty
-D message.no-color
32 changes: 32 additions & 0 deletions tests/misc/projects/Issue11753/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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<Bar>) -> Void should be () -> Unknown<0>
| have: { doWithBar: (?...) -> ... }
| want: { doWithBar: () -> ... }

Loading