Skip to content

Commit 70e25f7

Browse files
committed
Fix issue where capitalised type variables were only allowed in certain positions.
Fixes rescript-lang#6759
1 parent 74a4bf8 commit 70e25f7

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- Fix issue where optional labels were not taken into account when disambiguating record value construction. https://github.com/rescript-lang/rescript-compiler/pull/6798
4040
- Fix issue in gentype when type `Jsx.element` surfaces to the user. https://github.com/rescript-lang/rescript-compiler/pull/6808
4141
- Fix inclusion check (impl vs interface) for untagged variants, and fix the outcome printer to show tags. https://github.com/rescript-lang/rescript-compiler/pull/6669
42+
- Fix issue where capitalised type variables were only allowed in certain positions. https://github.com/rescript-lang/rescript-compiler/pull/6820
4243

4344
#### :house: Internal
4445

jscomp/syntax/src/res_core.ml

+7-3
Original file line numberDiff line numberDiff line change
@@ -4048,7 +4048,9 @@ and parse_type_var_list p =
40484048
match p.Parser.token with
40494049
| SingleQuote ->
40504050
Parser.next p;
4051-
let lident, loc = parse_lident p in
4051+
let lident, loc =
4052+
parse_ident ~msg:ErrorMessages.type_param ~start_pos:p.start_pos p
4053+
in
40524054
let var = Location.mkloc lident loc in
40534055
loop p (var :: vars)
40544056
| _ -> List.rev vars
@@ -4220,7 +4222,9 @@ and parse_type_alias p typ =
42204222
| As ->
42214223
Parser.next p;
42224224
Parser.expect SingleQuote p;
4223-
let ident, _loc = parse_lident p in
4225+
let ident, _loc =
4226+
parse_ident ~msg:ErrorMessages.type_param ~start_pos:p.start_pos p
4227+
in
42244228
(* TODO: how do we parse attributes here? *)
42254229
Ast_helper.Typ.alias
42264230
~loc:(mk_loc typ.Parsetree.ptyp_loc.loc_start p.prev_end_pos)
@@ -5029,7 +5033,7 @@ and parse_type_constraint p =
50295033
Parser.next p;
50305034
Parser.expect SingleQuote p;
50315035
match p.Parser.token with
5032-
| Lident ident ->
5036+
| Lident ident | Uident ident ->
50335037
let ident_loc = mk_loc start_pos p.end_pos in
50345038
Parser.next p;
50355039
Parser.expect Equal p;

jscomp/syntax/tests/parsing/grammar/typexpr/expected/typeconstr.res.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,10 @@ let (t : < age: int [@attr ] > list) = x
5555
let (t : < age: int [@attr ] ;.. > list) = x
5656
let (t : < age: int ;name: string ;.. > list) = x
5757
let (t : < age: int [@attr ] ;name: string [@attr ] ;.. > list) = x
58-
let (t : string list) = x
58+
let (t : string list) = x
59+
type nonrec ('T, 'E) id_6 =
60+
| Ok of 'T
61+
| Err of {
62+
payload: 'E }
63+
let foo (x : int as 'X) = x
64+
module type A = (Foo with type t = 'X constraint 'X = int)

jscomp/syntax/tests/parsing/grammar/typexpr/typeconstr.res

+9
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ let t: list<{.. @attr "age": int, @attr "name": string,}> = x // Note: this comp
5959

6060
// >= isn't an infix op
6161
let t: list<string>= x
62+
63+
// capitalised type variable in record
64+
type id_6<'T, 'E> = | Ok('T) | Err({payload: 'E})
65+
66+
// capitalised type variable in as pattern
67+
let foo = (x: int as 'X) => x
68+
69+
// capitalised type variable in type constraint
70+
module type A = Foo with type t = 'X constraint 'X = int

0 commit comments

Comments
 (0)