File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ exception UnknownVariable of string
20
20
exception WrongTypePrefixOperation of string * string
21
21
exception WrongTypePostfixOperation of string
22
22
exception WrongInvokedArgumentsLength of string
23
+ exception WrongTypeArrayInitList of string * string
23
24
exception WrongTypesAssignOperation of string * string * string
24
25
exception WrongTypeCondOperation of string
25
26
exception WrongTypesOperation of string * string * string
Original file line number Diff line number Diff line change @@ -141,6 +141,16 @@ let verify_call_expr meth_name args env class_name =
141
141
| WrongInvokedArgumentsLength s -> raise(WrongInvokedArgumentsLength (s))
142
142
end
143
143
144
+ let rec verify_array_init_list el =
145
+ match el with
146
+ | [] -> ()
147
+ | h ::t ->
148
+ (match t with
149
+ | [] -> ()
150
+ | h1 ::t1 ->
151
+ if h.etype <> h1.etype then
152
+ raise(WrongTypeArrayInitList (stringOfOpt h.etype, stringOfOpt h1.etype)));
153
+ verify_array_init_list t
144
154
145
155
146
156
(* check the type of the expressions *)
@@ -206,7 +216,13 @@ let rec verify_expression env current_env e =
206
216
e.etype < - verify_value v
207
217
| Name s ->
208
218
e.etype < - verify_name s env current_env
209
- | ArrayInit el -> () (* TODO*)
219
+ | ArrayInit el ->
220
+ List. iter (verify_expression env current_env) el;
221
+ (* check the type of each element which is in an array list is same *)
222
+ verify_array_init_list el;
223
+ e.etype < -
224
+ (match (List. hd el).etype with
225
+ | Some (t ) -> Some (Array (t, 1 )))
210
226
| Array (e ,el ) -> () (* TODO*)
211
227
| AssignExp (e1 ,op ,e2 ) ->
212
228
verify_expression env current_env e1;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public I(int e) {
21
21
boolean test = my instanceof I ;
22
22
int condop = (1 == 2 ) ? 1 : 5 ;
23
23
int [] arr = new int [5 ];
24
+ int [] arr2 = {1 ,2 ,8.5f };
24
25
private String func1 (int a ) {
25
26
int b = 1 ;
26
27
b += (5 +4 );
You can’t perform that action at this time.
0 commit comments