Skip to content

Commit

Permalink
[typer] constrain-mono all the things
Browse files Browse the repository at this point in the history
closes #9556
  • Loading branch information
Simn committed Jun 11, 2020
1 parent ffd9c58 commit 132c899
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/typing/calls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ let rec acc_get ctx g p =
let f = match c.cl_kind with
| KAbstractImpl a when Meta.has Meta.Enum a.a_meta ->
(* Enum abstracts have to apply their type parameters because they are basically statics with type params (#8700). *)
let monos = List.map (fun _ -> mk_mono()) a.a_params in
let monos = Monomorph.spawn_constrained_monos (fun t -> t) a.a_params in
apply_params a.a_params monos;
| _ -> (fun t -> t)
in
Expand Down
7 changes: 4 additions & 3 deletions src/typing/matcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ module Pattern = struct
let e1 = type_expr ctx e1 (WithType.with_type t) in
begin match e1.eexpr,follow e1.etype with
| TField(_, FEnum(en,ef)),TFun(_,TEnum(_,tl)) ->
let monos = List.map (fun _ -> mk_mono()) ef.ef_params in
let map t = apply_params en.e_params tl (apply_params ef.ef_params monos t) in
let map = apply_params en.e_params tl in
let monos = Monomorph.spawn_constrained_monos map ef.ef_params in
let map t = map (apply_params ef.ef_params monos t) in
unify ctx (map ef.ef_type) e1.etype e1.epos;
let args = match follow e1.etype with
| TFun(args,r) ->
Expand Down Expand Up @@ -959,7 +960,7 @@ module Compile = struct
let rec get_sub_subjects mctx e con arg_positions =
match fst con with
| ConEnum(en,ef) ->
let tl = List.map (fun _ -> mk_mono()) en.e_params in
let tl = Monomorph.spawn_constrained_monos (fun t -> t) en.e_params in
let t_en = TEnum(en,tl) in
let e = if not (type_iseq t_en e.etype) then mk (TCast(e,None)) t_en e.epos else e in
begin match follow ef.ef_type with
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typeloadFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ let bind_var (ctx,cctx,fctx) cf e =
let e = require_constant_expression e "Inline variable initialization must be a constant value" in
begin match c.cl_kind with
| KAbstractImpl a when Meta.has Meta.Enum cf.cf_meta && Meta.has Meta.Enum a.a_meta ->
unify ctx t (TAbstract(a,(List.map (fun _ -> mk_mono()) a.a_params))) p;
unify ctx t (TAbstract(a,(Monomorph.spawn_constrained_monos (fun t -> t) a.a_params))) p;
let e1 = match e.eexpr with TCast(e1,None) -> e1 | _ -> e in
unify ctx e1.etype a.a_this e1.epos
| _ ->
Expand Down Expand Up @@ -905,7 +905,7 @@ let check_abstract (ctx,cctx,fctx) c cf fd t ret p =
match cctx.abstract with
| Some a ->
let m = mk_mono() in
let ta = TAbstract(a, List.map (fun _ -> mk_mono()) a.a_params) in
let ta = TAbstract(a,Monomorph.spawn_constrained_monos (fun t -> t) a.a_params) in
let tthis = if fctx.is_abstract_member || Meta.has Meta.To cf.cf_meta then monomorphs a.a_params a.a_this else a.a_this in
let allows_no_expr = ref (Meta.has Meta.CoreType a.a_meta) in
let rec loop ml =
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ let rec type_binop ctx op e1 e2 is_assign_op with_type p =
]) t p
| AKUsing(ef,c,cf,et,_) ->
(* abstract setter + getter *)
let ta = match c.cl_kind with KAbstractImpl a -> TAbstract(a, List.map (fun _ -> mk_mono()) a.a_params) | _ -> die "" __LOC__ in
let ta = match c.cl_kind with KAbstractImpl a -> TAbstract(a,Monomorph.spawn_constrained_monos (fun t -> t) a.a_params) | _ -> die "" __LOC__ in
let ret = match follow ef.etype with
| TFun([_;_],ret) -> ret
| _ -> error "Invalid field type for abstract setter" p
Expand Down Expand Up @@ -1396,7 +1396,7 @@ and type_access ctx e p mode =
| TTypeExpr (TClassDecl c) ->
if mode = MSet then error "Cannot set constructor" p;
if mode = MCall then error ("Cannot call constructor like this, use 'new " ^ (s_type_path c.cl_path) ^ "()' instead") p;
let monos = List.map (fun _ -> mk_mono()) (match c.cl_kind with KAbstractImpl a -> a.a_params | _ -> c.cl_params) in
let monos = Monomorph.spawn_constrained_monos (fun t -> t) (match c.cl_kind with KAbstractImpl a -> a.a_params | _ -> c.cl_params) in
let ct, cf = get_constructor ctx c monos p in
check_constructor_access ctx c cf p;
let args = match follow ct with TFun(args,ret) -> args | _ -> die "" __LOC__ in
Expand Down
8 changes: 8 additions & 0 deletions tests/misc/projects/Issue9556/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Main<T:Int> {
static public function main() {
var f = Main.new;
f("foo");
}

function new(t:T) {}
}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue9556/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-main Main
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue9556/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Main.hx:4: characters 5-10 : Constraint check failure for Main.T
Main.hx:4: characters 5-10 : String should be Int
Main.hx:4: characters 5-10 : For function argument 't'

0 comments on commit 132c899

Please sign in to comment.