소스 검색

optional static variable type.

Nicolas Cannasse 20 년 전
부모
커밋
bb41e11367
3개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 1
      ast.ml
  2. 1 1
      parser.ml
  3. 6 1
      typer.ml

+ 1 - 1
ast.ml

@@ -176,7 +176,7 @@ type access =
 	| AStatic
 
 type class_field =
-	| FVar of string * access list * type_path * expr option
+	| FVar of string * access list * type_path option * expr option
 	| FFun of string * access list * func
 
 type type_param_flag =

+ 1 - 1
parser.ml

@@ -190,7 +190,7 @@ and parse_enum_param = parser
 and parse_class_field = parser
 	| [< l = parse_cf_rights []; s >] ->
 		match s with parser
-		| [< '(Kwd Var,p1); '(Const (Ident name),_); '(DblDot,_); t = parse_type_path; s >] -> 
+		| [< '(Kwd Var,p1); '(Const (Ident name),_); t = parse_type_opt; s >] ->			
 			let e , p2 = (match s with parser
 			| [< '(Binop OpAssign,_) when List.mem AStatic l; e = expr; p2 = semicolon >] -> Some e , p2
 			| [< '(Semicolon,p2) >] -> None , p2

+ 6 - 1
typer.ml

@@ -977,7 +977,12 @@ let init_class ctx c p types herits fields =
 	let loop_cf f p =
 		match f with
 		| FVar (name,access,t,e) ->
-			let t = load_type ctx p t in
+			let t = (match t with
+				| None -> 
+					if not (List.mem AStatic access) then error ("Type required for member variable " ^ name) p;
+					mk_mono()
+				| Some t -> load_type ctx p t
+			) in
 			let cf = {
 				cf_name = name;
 				cf_type = t;