Skip to content

Commit

Permalink
[hxb] introduce TPHUnbound to avoid crashes on such error state
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed May 14, 2024
1 parent 3109257 commit 24b4599
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@ class hxb_reader
local_type_parameters.(k).ttp_type
| 4 ->
t_dynamic
| 5 ->
let path = self#read_path in
(mk_type_param { null_class with cl_path = path } TPHUnbound None None).ttp_type
| 10 ->
let c = self#read_class_ref in
c.cl_type
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1096,14 +1096,18 @@ module HxbWriter = struct
writer.wrote_local_type_param <- true;
Chunk.write_u8 writer.chunk 3;
Chunk.write_uleb128 writer.chunk index;
| TPHUnbound ->
raise Not_found
end with Not_found ->
(try ignore(IdentityPool.get writer.unbound_ttp ttp) with Not_found -> begin
ignore(IdentityPool.add writer.unbound_ttp ttp ());
let p = file_pos (Path.UniqueKey.lazy_path writer.current_module.m_extra.m_file) in
let msg = Printf.sprintf "Unbound type parameter %s" (s_type_path ttp.ttp_class.cl_path) in
writer.warn WUnboundTypeParameter msg p
end);
Chunk.write_u8 writer.chunk 4; (* TDynamic None *)
writer.wrote_local_type_param <- true;
Chunk.write_u8 writer.chunk 5;
write_path writer ttp.ttp_class.cl_path;
end

(*
Expand Down Expand Up @@ -1661,6 +1665,7 @@ module HxbWriter = struct
| TPHEnumConstructor -> 3
| TPHAnonField -> 4
| TPHLocal -> 5
| TPHUnbound -> 6
in
Chunk.write_u8 writer.chunk i
in
Expand Down
1 change: 1 addition & 0 deletions src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ module Printer = struct
| TPHEnumConstructor -> "TPHEnumConstructor"
| TPHAnonField -> "TPHAnonField"
| TPHLocal -> "TPHLocal"
| TPHUnbound -> "TPHUnbound"

let s_type_param tabs ttp =
s_record_fields tabs [
Expand Down
1 change: 1 addition & 0 deletions src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type type_param_host =
| TPHEnumConstructor
| TPHAnonField
| TPHLocal
| TPHUnbound

type cache_bound_object =
| Resource of string * string
Expand Down
3 changes: 2 additions & 1 deletion src/typing/typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ and type_type_params ctx host path p tpl =
| TPHMethod
| TPHEnumConstructor
| TPHAnonField
| TPHLocal ->
| TPHLocal
| TPHUnbound ->
display_error ctx.com "Default type parameters are only supported on types" (pos ct)
end;
check_param_constraints ctx t (fun t -> t) ttp (pos ct);
Expand Down

0 comments on commit 24b4599

Please sign in to comment.