diff --git a/compiler.ml b/compiler.ml index 8c84d41..e832c43 100644 --- a/compiler.ml +++ b/compiler.ml @@ -14,7 +14,7 @@ let rec compile_expr ?(label = "") e env k li = in let rec compile_array_expr la env k li loc = match la with - | [] -> error loc "empty array" + | [] -> [""] | [e] -> compile_expr e env k li | e::es -> compile_expr e env k li @ ["PUSH"] @ compile_array_expr es env k li loc in @@ -40,7 +40,6 @@ let rec compile_expr ?(label = "") e env k li = | Ebinop (_,_,Bor,e1,e2) -> compile_binop_expr e1 e2 "or" env k li @ li | Eref (_,_,e) -> compile_expr e env k li @ ["MAKEBLOCK 1"] @ li | Ederef (loc,_,(typ,i)) -> compile_expr (Eident (loc,typ,(typ,i))) env k li @ ["GETFIELD 0"] @ li - | Earray (loc,_,[]) -> error loc "empty array" | Earray (loc,_,l) -> compile_array_expr (List.rev l) env k li loc @ ["MAKEBLOCK " ^ string_of_int (List.length l)] @ li | Eaget (loc,_,(typ,i),e) -> let tmp = "_tmp_" ^ string_of_int (counter ()) in diff --git a/parser.mly b/parser.mly index d1a1119..60eac16 100644 --- a/parser.mly +++ b/parser.mly @@ -78,6 +78,7 @@ expr : ; expr_list : + | { [] } | e=expr { [e] } | e=expr COMMA l=expr_list { e :: l } ; diff --git a/tests/ty_err_41-0.txt b/tests/ty_err_41-0.txt new file mode 100644 index 0000000..9f846ea --- /dev/null +++ b/tests/ty_err_41-0.txt @@ -0,0 +1,2 @@ +let a = {} in + print a[0]