فهرست منبع

allow implementing interfaces with inline methods

Nicolas Cannasse 16 سال پیش
والد
کامیت
a66e45eb44
2فایلهای تغییر یافته به همراه6 افزوده شده و 2 حذف شده
  1. 1 0
      doc/CHANGES.txt
  2. 5 2
      typeload.ml

+ 1 - 0
doc/CHANGES.txt

@@ -53,6 +53,7 @@ TODO :
 	php: added support for native Iterator and IteratorAggregate interfaces
 	all : added --display classes and --display keywords
 	all : fixed issue with optional parameters in inline functions
+	all : allow implementing interfaces with inline methods
 
 2009-03-22: 2.03
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php

+ 5 - 2
typeload.ml

@@ -338,8 +338,10 @@ let rec check_interface ctx c p intf params =
 			let p = (match f2.cf_expr with None -> p | Some e -> e.epos) in
 			if f.cf_public && not f2.cf_public then
 				display_error ctx ("Field " ^ i ^ " should be public as requested by " ^ s_type_path intf.cl_path) p
-			else if f2.cf_get <> f.cf_get || (f2.cf_set <> f.cf_set && (f2.cf_set,f.cf_set) <> (NeverAccess,NoAccess)) then
-				display_error ctx ("Field " ^ i ^ " has different property access than in " ^ s_type_path intf.cl_path) p
+			else if not (match f2.cf_get, f.cf_get with InlineAccess, NormalAccess -> true | a,b -> a = b) then
+				display_error ctx ("Field " ^ i ^ " has different property access than in " ^ s_type_path intf.cl_path ^ " (" ^ s_access f2.cf_get ^ " should be " ^ s_access f.cf_get ^ ")") p
+			else if not (match f2.cf_set, f.cf_set with NeverAccess, NoAccess -> true | NeverAccess, MethodAccess false -> f2.cf_get = InlineAccess | a,b -> a = b) then
+				display_error ctx ("Field " ^ i ^ " has different property access than in " ^ s_type_path intf.cl_path ^ " (" ^ s_access f2.cf_set ^ " should be " ^ s_access f.cf_set ^ ")") p			
 			else try
 				valid_redefinition ctx f2 t2 f (apply_params intf.cl_types params f.cf_type)
 			with
@@ -616,6 +618,7 @@ let init_class ctx c p herits fields =
 			) params in
 			let stat = List.mem AStatic access in
 			let inline = List.mem AInline access in
+			if inline && c.cl_interface then error "You can't declare inline methods in interfaces" p;
 			let parent = (if not stat then get_parent c name else None) in
 			let dynamic = List.mem ADynamic access || (match parent with Some { cf_set = MethodAccess true } -> true | _ -> false) in
 			let ctx = { ctx with