Skip to content

Commit 97e52db

Browse files
committed
Fix arity detection for arrows returning nested generics
1 parent b68efad commit 97e52db

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ let is_es6_arrow_expression ~in_ternary p =
362362
(match state.Parser.token with
363363
(* arrived at `() :typ<` here *)
364364
| LessThan ->
365+
Scanner.set_diamond_mode state.scanner;
365366
Parser.next state;
366-
go_to_closing GreaterThan state
367+
go_to_closing GreaterThan state;
368+
Scanner.pop_mode state.scanner Diamond
367369
| _ -> ());
368370
match state.Parser.token with
369371
(* arrived at `() :typ =>` or `() :typ<'a,'b> =>` here *)

tests/syntax_tests/data/parsing/grammar/expressions/arrow.res

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,3 @@ type f = int => unit;
110110
let a = fn(_ => (): f);
111111

112112
let returnsArrayOption = (): option<array<string>> => Some(["foo"])
113-
let usesIt = returnsArrayOption()

tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ type nonrec u = unit
7474
let un = (() : u)
7575
type nonrec ('a, 'b) d = ('a * 'b)
7676
let c [arity:1]() = ((1, 2) : ('a, 'b) d)
77-
let arr () = ([||] : int nullable array)
77+
let arr [arity:1]() = ([||] : int nullable array)
7878
let fn [arity:1]f = f
7979
type nonrec f = int -> unit (a:1)
8080
let a = fn (fun [arity:1]_ -> () : f)
81-
let returnsArrayOption () = (Some [|{js|foo|js}|] : string array option)
82-
let usesIt = returnsArrayOption ()
81+
let returnsArrayOption [arity:1]() =
82+
(Some [|{js|foo|js}|] : string array option)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
function foo() {
5+
return ["foo"];
6+
}
7+
8+
let bar = ["foo"];
9+
10+
function nested() {
11+
return 1;
12+
}
13+
14+
let baz = 1;
15+
16+
export {
17+
foo,
18+
bar,
19+
nested,
20+
baz,
21+
}
22+
/* No side effect */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let foo = (): option<array<string>> => Some(["foo"])
2+
let bar = foo()
3+
4+
let nested = (): option<option<int>> => Some(Some(1))
5+
let baz = nested()

0 commit comments

Comments
 (0)