Skip to content

Commit

Permalink
improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wies committed Nov 21, 2024
1 parent 92a0010 commit 756dd13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/ast/astDef.ml
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ module Expr = struct
let to_int expr =
match expr with
| App (Int i, _, _) -> Int.of_int64_exn i
| _ -> Error.error (to_loc expr) "Expected Int expression"
| _ -> Error.type_error (to_loc expr) "Expected Int constant"

let unfold_tuple expr =
match expr with
Expand Down
11 changes: 7 additions & 4 deletions lib/frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ let rec process_expr (expr : expr) (expected_typ : type_expr) : expr Rewriter.t
(* backpropagate typ2 to expr1 if needed *)
let expected_typ1 =
let ty = match constr with
| TupleLookUp ->
let _lookup_type = Type.tuple_lookup typ1 (Expr.to_int expr2) in
(* above lookup checks well-formedness of typ1 *)
typ1
| TupleLookUp ->
let idx = Expr.to_int expr2 in
begin match typ1 with
| App (Prod, ts, _) when idx < List.length ts && idx >= 0 -> typ1
| App (Prod, _, _) -> Error.type_error (Expr.to_loc expr2) "Index out of bounds"
| App _ -> Error.type_error (Expr.to_loc expr1) "Expected product type"
end
| MapLookUp -> Type.(map typ2 (Type.map_codom typ1))
| Diff | Union | Inter | Plus | Minus | Mult | Div | Mod | Subseteq
| Eq | Gt | Lt | Geq | Leq ->
Expand Down
5 changes: 4 additions & 1 deletion test/ci/front-end/fail/tuple.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
$ dune exec -- raven --shh ./tuple.rav
[Error] Index out of bounds
[Error] File "./tuple.rav", line 7, columns 20-22:
7 | var zz: Int := x#2;
^^
Type Error: Index out of bounds.
[1]

0 comments on commit 756dd13

Please sign in to comment.