Skip to content

Commit

Permalink
Fix precedence of stack_ keyword (#92)
Browse files Browse the repository at this point in the history
the two main bugs in the PR description, plus some expressions nobody
should write, but might write anyway
  • Loading branch information
dvulakh authored Jan 15, 2025
1 parent 35aaa33 commit 304977b
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2464,10 +2464,15 @@ end = struct
( Pexp_apply _ | Pexp_fun _ | Pexp_function _ | Pexp_lazy _
| Pexp_new _ | Pexp_tuple _
| Pexp_construct (_, Some _)
| Pexp_cons _ | Pexp_infix _ | Pexp_prefix _ | Pexp_stack _
| Pexp_let _ | Pexp_letop _ | Pexp_letopen _ | Pexp_letmodule _
| Pexp_send _ | Pexp_setfield _ | Pexp_ifthenelse _
| Pexp_variant (_, Some _) )
; _ } ) ->
true
| Exp {pexp_desc= Pexp_apply _; _}, {pexp_desc= Pexp_stack _; _} -> true
| ( Exp {pexp_desc= Pexp_apply _ | Pexp_construct _; _}
, {pexp_desc= Pexp_stack _; _} ) ->
true
| ( Str
{ pstr_desc=
Pstr_value
Expand Down
27 changes: 27 additions & 0 deletions test/passing/tests/stack-erased.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,30 @@ let x =
(* 12 *)
(Foo x)) )
;;

(* Constructor precedence *)

let x = Foo (stack_ ((), ()))
let x = stack_ (() :: [])

(* Tuples *)

let x = stack_ (1, 2)
let x = stack_ #(1, 2)
let x = stack_ (~x:1, ~y:2)

(* Expressions rejected by the typechecker *)

let x = stack_ (x + y)
let x = stack_ (-x)
let x = stack_ (stack_ (Foo x))

let x =
stack_
(let y = 1 in
Some y)
;;

let x = stack_ (c#x)
let x = stack_ (r.x <- x)
let x = stack_ (if x then y else z)
32 changes: 32 additions & 0 deletions test/passing/tests/stack-erased.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,35 @@ let x =
(* 12 *)
Foo
x ) )

(* Constructor precedence *)

let x = Foo ((), ())

let x = () :: []

(* Tuples *)

let x = (1, 2)

let x = #(1, 2)

let x = (~x:1, ~y:2)

(* Expressions rejected by the typechecker *)

let x = x + y

let x = -x

let x = Foo x

let x =
let y = 1 in
Some y

let x = c#x

let x = r.x <- x

let x = if x then y else z
34 changes: 34 additions & 0 deletions test/passing/tests/stack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,37 @@ let x = stack_ (stack_ ( 2 , stack_ "hello" ), ~x:(stack_ (Foo x)))

let x = (* 1 *) stack_ (* 2 *) ((* 3 *) stack_ (* 4 *) ((* 5 *) 1 (* 6 *),
stack_ (* 7 *) "hello" (* 8 *)) (* 9 *), (* 10 *) ~x:((* 11 *)stack_ (* 12 *) (Foo x)))

(* Constructor precedence *)

let x = Foo (stack_ ((), ()))

let x = stack_ (() :: [])

(* Tuples *)

let x = stack_ (1, 2)

let x = stack_ #(1, 2)

let x = stack_ (~x:1, ~y:2)

(* Expressions rejected by the typechecker *)

let x = stack_ (x + y)

let x = stack_ (-x)

let x = stack_ (stack_ (Foo x))

let x = stack_ (let y = 1 in Some y)

let x = stack_ (c # x)

let x = stack_ (r.x <- x)

let x = stack_ (
if x
then y
else z
)
27 changes: 27 additions & 0 deletions test/passing/tests/stack.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,30 @@ let x =
(* 12 *)
(Foo x)) )
;;

(* Constructor precedence *)

let x = Foo (stack_ ((), ()))
let x = stack_ (() :: [])

(* Tuples *)

let x = stack_ (1, 2)
let x = stack_ #(1, 2)
let x = stack_ (~x:1, ~y:2)

(* Expressions rejected by the typechecker *)

let x = stack_ (x + y)
let x = stack_ (-x)
let x = stack_ (stack_ (Foo x))

let x =
stack_
(let y = 1 in
Some y)
;;

let x = stack_ (c#x)
let x = stack_ (r.x <- x)
let x = stack_ (if x then y else z)
33 changes: 33 additions & 0 deletions test/passing/tests/stack.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,36 @@ let x =
(* 11 *)
(* 12 *)
(Foo x ) ) )

(* Constructor precedence *)

let x = Foo (stack_ ((), ()))

let x = stack_ (() :: [])

(* Tuples *)

let x = stack_ (1, 2)

let x = stack_ #(1, 2)

let x = stack_ (~x:1, ~y:2)

(* Expressions rejected by the typechecker *)

let x = stack_ (x + y)

let x = stack_ (-x)

let x = stack_ (stack_ (Foo x))

let x =
stack_
(let y = 1 in
Some y )

let x = stack_ (c#x)

let x = stack_ (r.x <- x)

let x = stack_ (if x then y else z)

0 comments on commit 304977b

Please sign in to comment.