Skip to content

Commit

Permalink
Empty array check only in typer
Browse files Browse the repository at this point in the history
  • Loading branch information
epatrizio committed Sep 15, 2022
1 parent 4752881 commit dcb36a8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ expr :
;

expr_list :
| { [] }
| e=expr { [e] }
| e=expr COMMA l=expr_list { e :: l }
;
Expand Down
2 changes: 2 additions & 0 deletions tests/ty_err_41-0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let a = {} in
print a[0]

0 comments on commit dcb36a8

Please sign in to comment.