Skip to content

Commit

Permalink
Fixed typing of map compr expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
EkanshdeepGupta committed May 8, 2024
1 parent 6a4bb40 commit e4733e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/frontend/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,14 @@ let rec process_expr (expr: expr) (expected_typ: type_expr) : expr Rewriter.t =
| [v] -> v
| _ -> Error.type_error (Expr.to_loc expr) "Map/Set compr only take one quantified variable"
in
let* inner_expr = process_expr inner_expr Type.any in

let inner_expr_expected_typ = match expected_typ with
| App (Set, [tp], _) -> Type.bool
| App (Map, [_; tp], _) -> tp
| _tp -> Error.type_error (Expr.to_loc expr) ("Expected set or map type; found " ^ Type.to_string _tp)
in

let* inner_expr = process_expr inner_expr inner_expr_expected_typ in
let inner_expr_type = Expr.to_type inner_expr in

let expr_typ =
Expand Down
5 changes: 5 additions & 0 deletions test/ci/front-end/map_empty_set.rav
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
proc p() {
var x: Map[Int, Set[Int]] = {| k:Int :: {||} |};

var y: Set[Int] = {| k:Int :: k > 5 |};
}
2 changes: 2 additions & 0 deletions test/ci/front-end/map_empty_set.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ dune exec -- raven --shh ./map_empty_set.rav
Verification successful.

0 comments on commit e4733e3

Please sign in to comment.