Browse Source

[hxb] introduce TPHUnbound to avoid crashes on subsequent builds

See #11628 for context
Rudy Ges 1 year ago
parent
commit
0e96faee8e

+ 3 - 0
src/compiler/hxb/hxbReader.ml

@@ -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

+ 6 - 1
src/compiler/hxb/hxbWriter.ml

@@ -1096,6 +1096,8 @@ 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 ());
@@ -1103,7 +1105,9 @@ module HxbWriter = struct
 				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
 
 	(*
@@ -1661,6 +1665,7 @@ module HxbWriter = struct
 				| TPHEnumConstructor -> 3
 				| TPHAnonField -> 4
 				| TPHLocal -> 5
+				| TPHUnbound -> 6
 			in
 			Chunk.write_u8 writer.chunk i
 		in

+ 1 - 0
src/core/tPrinting.ml

@@ -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 [

+ 1 - 0
src/core/tType.ml

@@ -54,6 +54,7 @@ type type_param_host =
 	| TPHEnumConstructor
 	| TPHAnonField
 	| TPHLocal
+	| TPHUnbound
 
 type cache_bound_object =
 	| Resource of string * string

+ 2 - 1
src/typing/typeload.ml

@@ -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);