Browse Source

handle overloads in structural subtyping (fixed issue #1035)

Simon Krajewski 13 years ago
parent
commit
679a23ed28
2 changed files with 7 additions and 0 deletions
  1. 5 0
      type.ml
  2. 2 0
      typecore.ml

+ 5 - 0
type.ml

@@ -633,6 +633,7 @@ type unify_error =
 	| Cant_force_optional
 	| Invariant_parameter of t * t
 	| Constraint_failure of string
+	| Missing_overload of tclass_field * t
 	| Unify_custom of string
 
 exception Unify_error of unify_error list
@@ -891,6 +892,10 @@ let rec unify a b =
 					unify_with_access (apply_params c.cl_types tl ft) f2
 				with
 					Unify_error l -> error (invalid_field n :: l));
+				List.iter (fun f2o ->
+					if not (List.exists (fun f1o -> type_iseq f1o.cf_type f2o.cf_type) (f1 :: f1.cf_overloads))
+					then error [Missing_overload (f1, f2o.cf_type)]
+				) f2.cf_overloads;
 				(match f1.cf_kind with
 				| Method MethInline ->
 					if (c.cl_extern || has_meta ":extern" f1.cf_meta) && not (has_meta ":runtime" f1.cf_meta) then error [Has_no_runtime_field (a,n)];

+ 2 - 0
typecore.ml

@@ -141,6 +141,8 @@ let unify_error_msg ctx = function
 		"Type parameters are invariant"
 	| Constraint_failure name ->
 		"Constraint check failure for " ^ name
+	| Missing_overload (cf, t) ->
+		cf.cf_name ^ " has no overload for " ^ s_type ctx t
 	| Unify_custom msg ->
 		msg