Ver código fonte

[typer] use distinct tvar_kind for abstract this

see #8712
Simon Krajewski 2 anos atrás
pai
commit
e856e79214

+ 1 - 0
src/core/tType.ml

@@ -126,6 +126,7 @@ and tvar_kind =
 	| VInlined
 	| VInlinedConstructorVariable
 	| VExtractorVariable
+	| VAbstractThis
 
 and tvar = {
 	mutable v_id : int;

+ 1 - 1
src/typing/functionArguments.ml

@@ -46,7 +46,7 @@ class function_arguments
 	(syntax : (placed_name * bool * metadata * type_hint option * expr option) list)
 =
 	let with_default =
-		let l = List.mapi (fun i ((name,pn),opt,m,t,eo) ->
+		let l = List.mapi (fun i ((name,pn),opt,_,t,eo) ->
 			let t = type_arg i opt t pn in
 			let t,eo = type_function_arg ctx t eo opt pn in
 			(name,eo,t)

+ 1 - 1
src/typing/typeloadFields.ml

@@ -273,7 +273,7 @@ let transform_abstract_field com this_t a_t a f =
 	| FProp _ when not stat && not (Meta.has Meta.Enum f.cff_meta) ->
 		typing_error "Member property accessors must be get/set or never" p;
 	| FFun fu when fst f.cff_name = "new" && not stat ->
-		let init p = (EVars [mk_evar ~t:this_t ("this",null_pos)],p) in
+		let init p = (EVars [mk_evar ~t:this_t ~meta:([Meta.This,[],null_pos]) ("this",null_pos)],p) in
 		let cast e = (ECast(e,None)),pos e in
 		let ret p = (EReturn (Some (cast (EConst (Ident "this"),p))),p) in
 		let meta = (Meta.NoCompletion,[],null_pos) :: f.cff_meta in

+ 5 - 1
src/typing/typer.ml

@@ -704,7 +704,11 @@ and type_vars ctx vl p =
 					let e = AbstractCast.cast_or_unify ctx t e p in
 					Some e
 			) in
-			let v = add_local_with_origin ctx TVOLocalVariable n t pv in
+			let v = if Meta.has Meta.This ev.ev_meta then
+				add_local ctx VAbstractThis n t pv
+			else
+				add_local_with_origin ctx TVOLocalVariable n t pv
+			in
 			v.v_meta <- ev.ev_meta;
 			DisplayEmitter.check_display_metadata ctx v.v_meta;
 			if ev.ev_final then add_var_flag v VFinal;