Skip to content

Commit cad989f

Browse files
authored
Fix arity detection for arrows returning nested generics (#8064)
1 parent 394848f commit cad989f

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Rewatch: warnings for unsupported/unknown rescript.json fields. https://github.com/rescript-lang/rescript/pull/8031
2424
- Fix missing `ignore` function in some Stdlib modules. https://github.com/rescript-lang/rescript/pull/8060
2525
- Fix signature matching for externals when abstract alias hides function arity. https://github.com/rescript-lang/rescript/pull/8045
26+
- Fix arity detection for arrows returning nested generics. https://github.com/rescript-lang/rescript/pull/8064
2627

2728
#### :memo: Documentation
2829

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ let arr = (): array<nullable<int>> => []
107107

108108
let fn = f => f;
109109
type f = int => unit;
110-
let a = fn(_ => (): f);
110+
let a = fn(_ => (): f);
111+
112+
let returnsArrayOption = (): option<array<string>> => Some(["foo"])

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +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)
80-
let a = fn (fun [arity:1]_ -> () : f)
80+
let a = fn (fun [arity:1]_ -> () : f)
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://github.com/rescript-lang/rescript/issues/8055
2+
3+
let foo = (): option<array<string>> => Some(["foo"])
4+
let bar = foo()
5+
6+
let nested = (): option<option<int>> => Some(Some(1))
7+
let baz = nested()

0 commit comments

Comments
 (0)