浏览代码

allow access to fields of a type parameter which is constrained to a base class of the accessing class (fixed issue #1187)

Simon Krajewski 13 年之前
父节点
当前提交
a0a9a730aa
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      typer.ml

+ 6 - 1
typer.ml

@@ -139,7 +139,7 @@ let class_field ctx c pl name p =
 	raw_class_field (fun f -> field_type ctx c pl f p) c name
 
 (* checks if we can access to a given class field using current context *)
-let can_access ctx c cf stat =
+let rec can_access ctx c cf stat =
 	if cf.cf_public then
 		true
 	else
@@ -184,6 +184,11 @@ let can_access ctx c cf stat =
 		|| has ":access" ctx.curclass ctx.curfield (make_path c cf)
 	in
 	loop c
+	(* access is also allowed of we access a type parameter which is constrained to our (base) class *)
+	|| (match c.cl_kind with
+		| KTypeParameter tl ->
+			List.exists (fun t -> match follow t with TInst(c,_) -> loop c | _ -> false) tl
+		| _ -> false)
 
 (* removes the first argument of the class field's function type and all its overloads *)
 let prepare_using_field cf = match cf.cf_type with