Răsfoiți Sursa

don't allow structural subtyping with inlined extern fields

Nicolas Cannasse 13 ani în urmă
părinte
comite
48d9f2b7fa
2 a modificat fișierele cu 9 adăugiri și 2 ștergeri
  1. 7 2
      type.ml
  2. 2 0
      typecore.ml

+ 7 - 2
type.ml

@@ -612,6 +612,7 @@ type unify_error =
 	| Cannot_unify of t * t
 	| Invalid_field_type of string
 	| Has_no_field of t * string
+	| Has_no_runtime_field of t * string
 	| Has_extra_field of t * string
 	| Invalid_kind of string * field_kind * field_kind
 	| Invalid_visibility of string
@@ -871,10 +872,14 @@ let rec unify a b =
 				let ft, f1 = (try class_field c n with Not_found -> error [has_no_field a n]) in
 				if not (unify_kind f1.cf_kind f2.cf_kind) then error [invalid_kind n f1.cf_kind f2.cf_kind];
 				if f2.cf_public && not f1.cf_public then error [invalid_visibility n];
-				try
+				(try
 					unify_with_access (apply_params c.cl_types tl ft) f2
 				with
-					Unify_error l -> error (invalid_field n :: l)
+					Unify_error l -> error (invalid_field n :: l));
+				(match f1.cf_kind with
+				| Method MethInline when c.cl_extern || has_meta ":extern" f1.cf_meta ->
+					error [Has_no_runtime_field (a,n)]
+				| _ -> ());
 			) an.a_fields;
 			if !(an.a_status) = Opened then an.a_status := Closed;
 		with

+ 2 - 0
typecore.ml

@@ -105,6 +105,8 @@ let unify_error_msg ctx = function
 		"Invalid type for field " ^ s ^ " :"
 	| Has_no_field (t,n) ->
 		s_type ctx t ^ " has no field " ^ n
+	| Has_no_runtime_field (t,n) ->
+		s_type ctx t ^ "." ^ n ^ " is not accessible at runtime"
 	| Has_extra_field (t,n) ->
 		s_type ctx t ^ " has extra field " ^ n
 	| Invalid_kind (f,a,b) ->