Skip to content

Commit

Permalink
[typer] add MEmptyStructure to make it more explicit
Browse files Browse the repository at this point in the history
closes #9393
  • Loading branch information
Simn committed Jun 16, 2020
1 parent 5358840 commit 49c5095
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ and s_constraint = function
| MField cf -> Printf.sprintf "MField %s" cf.cf_name
| MType(t,_) -> Printf.sprintf "MType %s" (s_type_kind t)
| MOpenStructure -> "MOpenStructure"
| MEmptyStructure -> "MEmptyStructure"

let s_access is_read = function
| AccNormal -> "default"
Expand Down
1 change: 1 addition & 0 deletions src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ and tmono_constraint =
| MField of tclass_field
| MType of t * string option
| MOpenStructure
| MEmptyStructure

and tmono_constraint_kind =
| CUnknown
Expand Down
7 changes: 6 additions & 1 deletion src/core/tUnification.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module Monomorph = struct
(MField cf) :: l
) an.a_fields []
| TAnon _ ->
[MOpenStructure]
[MEmptyStructure]
| _ ->
[MType(t,name)]

Expand All @@ -80,6 +80,7 @@ module Monomorph = struct
let types = DynArray.create () in
let fields = ref PMap.empty in
let is_open = ref false in
let is_empty = ref false in
let rec check constr = match constr with
| MMono(m2,name) ->
begin match m2.tm_type with
Expand All @@ -94,12 +95,16 @@ module Monomorph = struct
DynArray.add types (t2,name)
| MOpenStructure ->
is_open := true
| MEmptyStructure ->
is_empty := true;
in
List.iter check m.tm_constraints;
if DynArray.length types > 0 then
CTypes (DynArray.to_list types)
else if not (PMap.is_empty !fields) || !is_open then
CStructural(!fields,!is_open)
else if !is_empty then
CStructural(PMap.empty,true)
else
CUnknown

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/src/unit/issues/Issue9593.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package unit.issues;
import unit.Test;

class Issue9593 extends Test {
function test() {
foo(function(res) res.error);
utest.Assert.pass();
}

static function foo<T:{}>(cb:T->Void):Void {}
}

0 comments on commit 49c5095

Please sign in to comment.