|
@@ -352,6 +352,7 @@ let rec using_field ctx mode e i p =
|
|
|
|
|
|
(* Resolves field [i] on typed expression [e] using the given [mode]. *)
|
|
(* Resolves field [i] on typed expression [e] using the given [mode]. *)
|
|
let rec type_field cfg ctx e i p mode =
|
|
let rec type_field cfg ctx e i p mode =
|
|
|
|
+ let pfield = if (e.epos = p) then p else {p with pmin = p.pmax - (String.length i)} in
|
|
let no_field() =
|
|
let no_field() =
|
|
if TypeFieldConfig.do_resume cfg then raise Not_found;
|
|
if TypeFieldConfig.do_resume cfg then raise Not_found;
|
|
let t = match follow e.etype with
|
|
let t = match follow e.etype with
|
|
@@ -370,9 +371,9 @@ let rec type_field cfg ctx e i p mode =
|
|
match t with
|
|
match t with
|
|
| TAbstract(a,_) when has_special_field a ->
|
|
| TAbstract(a,_) when has_special_field a ->
|
|
(* the abstract field is not part of the field list, which is only true when it has no expression (issue #2344) *)
|
|
(* the abstract field is not part of the field list, which is only true when it has no expression (issue #2344) *)
|
|
- display_error ctx ("Field " ^ i ^ " cannot be called directly because it has no expression") p;
|
|
|
|
|
|
+ display_error ctx ("Field " ^ i ^ " cannot be called directly because it has no expression") pfield;
|
|
| _ ->
|
|
| _ ->
|
|
- display_error ctx (StringError.string_error i (string_source t) (s_type (print_context()) t ^ " has no field " ^ i)) p;
|
|
|
|
|
|
+ display_error ctx (StringError.string_error i (string_source t) (s_type (print_context()) t ^ " has no field " ^ i)) pfield;
|
|
end;
|
|
end;
|
|
AKExpr (mk (TField (e,FDynamic i)) (mk_mono()) p)
|
|
AKExpr (mk (TField (e,FDynamic i)) (mk_mono()) p)
|
|
in
|
|
in
|
|
@@ -424,7 +425,7 @@ let rec type_field cfg ctx e i p mode =
|
|
| MCall,Var {v_read = AccCall } ->
|
|
| MCall,Var {v_read = AccCall } ->
|
|
()
|
|
()
|
|
| MCall, Var _ ->
|
|
| MCall, Var _ ->
|
|
- display_error ctx "Cannot access superclass variable for calling: needs to be a proper method" p
|
|
|
|
|
|
+ display_error ctx "Cannot access superclass variable for calling: needs to be a proper method" pfield
|
|
| MCall, _ ->
|
|
| MCall, _ ->
|
|
()
|
|
()
|
|
| MGet,Var _
|
|
| MGet,Var _
|
|
@@ -433,8 +434,8 @@ let rec type_field cfg ctx e i p mode =
|
|
| _, Method _ ->
|
|
| _, Method _ ->
|
|
display_error ctx "Cannot create closure on super method" p
|
|
display_error ctx "Cannot create closure on super method" p
|
|
| _ ->
|
|
| _ ->
|
|
- display_error ctx "Normal variables cannot be accessed with 'super', use 'this' instead" p);
|
|
|
|
- if not (can_access ctx c f false) && not ctx.untyped then display_error ctx ("Cannot access private field " ^ i) p;
|
|
|
|
|
|
+ display_error ctx "Normal variables cannot be accessed with 'super', use 'this' instead" pfield);
|
|
|
|
+ if not (can_access ctx c f false) && not ctx.untyped then display_error ctx ("Cannot access private field " ^ i) pfield;
|
|
field_access ctx mode f (match c2 with None -> FAnon f | Some (c,tl) -> FInstance (c,tl,f)) (apply_params c.cl_params params t) e p
|
|
field_access ctx mode f (match c2 with None -> FAnon f | Some (c,tl) -> FInstance (c,tl,f)) (apply_params c.cl_params params t) e p
|
|
with Not_found -> try
|
|
with Not_found -> try
|
|
begin match e.eexpr with
|
|
begin match e.eexpr with
|
|
@@ -464,7 +465,7 @@ let rec type_field cfg ctx e i p mode =
|
|
raise Not_found
|
|
raise Not_found
|
|
end
|
|
end
|
|
with Not_found ->
|
|
with Not_found ->
|
|
- if PMap.mem i c.cl_statics then error ("Cannot access static field " ^ i ^ " from a class instance") p;
|
|
|
|
|
|
+ if PMap.mem i c.cl_statics then error ("Cannot access static field " ^ i ^ " from a class instance") pfield;
|
|
no_field())
|
|
no_field())
|
|
| TDynamic t ->
|
|
| TDynamic t ->
|
|
(try
|
|
(try
|
|
@@ -474,12 +475,12 @@ let rec type_field cfg ctx e i p mode =
|
|
| TAnon a ->
|
|
| TAnon a ->
|
|
(try
|
|
(try
|
|
let f = PMap.find i a.a_fields in
|
|
let f = PMap.find i a.a_fields in
|
|
- if Meta.has Meta.Impl f.cf_meta && not (Meta.has Meta.Enum f.cf_meta) then display_error ctx "Cannot access non-static abstract field statically" p;
|
|
|
|
|
|
+ if Meta.has Meta.Impl f.cf_meta && not (Meta.has Meta.Enum f.cf_meta) then display_error ctx "Cannot access non-static abstract field statically" pfield;
|
|
if not (has_class_field_flag f CfPublic) && not ctx.untyped then begin
|
|
if not (has_class_field_flag f CfPublic) && not ctx.untyped then begin
|
|
match !(a.a_status) with
|
|
match !(a.a_status) with
|
|
| Closed | Extend _ -> () (* always allow anon private fields access *)
|
|
| Closed | Extend _ -> () (* always allow anon private fields access *)
|
|
| Statics c when can_access ctx c f true -> ()
|
|
| Statics c when can_access ctx c f true -> ()
|
|
- | _ -> display_error ctx ("Cannot access private field " ^ i) p
|
|
|
|
|
|
+ | _ -> display_error ctx ("Cannot access private field " ^ i) pfield
|
|
end;
|
|
end;
|
|
let fmode, ft = (match !(a.a_status) with
|
|
let fmode, ft = (match !(a.a_status) with
|
|
| Statics c -> FStatic (c,f), field_type ctx c [] f p
|
|
| Statics c -> FStatic (c,f), field_type ctx c [] f p
|
|
@@ -532,7 +533,7 @@ let rec type_field cfg ctx e i p mode =
|
|
(try
|
|
(try
|
|
let c = (match a.a_impl with None -> raise Not_found | Some c -> c) in
|
|
let c = (match a.a_impl with None -> raise Not_found | Some c -> c) in
|
|
let f = PMap.find i c.cl_statics in
|
|
let f = PMap.find i c.cl_statics in
|
|
- if not (can_access ctx c f true) && not ctx.untyped then display_error ctx ("Cannot access private field " ^ i) p;
|
|
|
|
|
|
+ if not (can_access ctx c f true) && not ctx.untyped then display_error ctx ("Cannot access private field " ^ i) pfield;
|
|
let field_type f =
|
|
let field_type f =
|
|
if not (Meta.has Meta.Impl f.cf_meta) then begin
|
|
if not (Meta.has Meta.Impl f.cf_meta) then begin
|
|
static_abstract_access_through_instance := true;
|
|
static_abstract_access_through_instance := true;
|
|
@@ -560,7 +561,7 @@ let rec type_field cfg ctx e i p mode =
|
|
AKNo f.cf_name
|
|
AKNo f.cf_name
|
|
| (MGet | MCall), _ ->
|
|
| (MGet | MCall), _ ->
|
|
let rec loop cfl = match cfl with
|
|
let rec loop cfl = match cfl with
|
|
- | [] -> error (Printf.sprintf "Field %s cannot be called on %s" f.cf_name (s_type (print_context()) e.etype)) p
|
|
|
|
|
|
+ | [] -> error (Printf.sprintf "Field %s cannot be called on %s" f.cf_name (s_type (print_context()) e.etype)) pfield
|
|
| cf :: cfl ->
|
|
| cf :: cfl ->
|
|
match follow (apply_params a.a_params pl (monomorphs cf.cf_params cf.cf_type)) with
|
|
match follow (apply_params a.a_params pl (monomorphs cf.cf_params cf.cf_type)) with
|
|
| TFun((_,_,t1) :: _,_) when type_iseq t1 (Abstract.get_underlying_type a pl) ->
|
|
| TFun((_,_,t1) :: _,_) when type_iseq t1 (Abstract.get_underlying_type a pl) ->
|
|
@@ -575,7 +576,7 @@ let rec type_field cfg ctx e i p mode =
|
|
let t = field_type f in
|
|
let t = field_type f in
|
|
begin match follow t with
|
|
begin match follow t with
|
|
| TFun((_,_,t1) :: _,_) -> ()
|
|
| TFun((_,_,t1) :: _,_) -> ()
|
|
- | _ -> error ("Invalid call to static function " ^ i ^ " through abstract instance") p
|
|
|
|
|
|
+ | _ -> error ("Invalid call to static function " ^ i ^ " through abstract instance") pfield
|
|
end;
|
|
end;
|
|
let ef = field_expr f t in
|
|
let ef = field_expr f t in
|
|
AKUsing (ef,c,f,e,false)
|
|
AKUsing (ef,c,f,e,false)
|
|
@@ -614,9 +615,9 @@ let rec type_field cfg ctx e i p mode =
|
|
if not (TypeFieldConfig.allow_resolve cfg) then raise Not_found;
|
|
if not (TypeFieldConfig.allow_resolve cfg) then raise Not_found;
|
|
get_resolve (mode = MSet)
|
|
get_resolve (mode = MSet)
|
|
with Not_found ->
|
|
with Not_found ->
|
|
- if !static_abstract_access_through_instance then error ("Invalid call to static function " ^ i ^ " through abstract instance") p
|
|
|
|
|
|
+ if !static_abstract_access_through_instance then error ("Invalid call to static function " ^ i ^ " through abstract instance") pfield
|
|
else no_field())
|
|
else no_field())
|
|
| _ ->
|
|
| _ ->
|
|
try using_field ctx mode e i p with Not_found -> no_field()
|
|
try using_field ctx mode e i p with Not_found -> no_field()
|
|
|
|
|
|
-let type_field_default_cfg = type_field TypeFieldConfig.default
|
|
|
|
|
|
+let type_field_default_cfg = type_field TypeFieldConfig.default
|