Skip to content

Commit 4749d88

Browse files
cristianoccknitt
authored andcommitted
Fix issue where capitalised type variables were only allowed in certain positions.
1 parent a7c32e5 commit 4749d88

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
@@ -26,6 +26,7 @@
2626
- Fix issue in gentype when type `Jsx.element` surfaces to the user. https://github.com/rescript-lang/rescript-compiler/pull/6808
2727
- 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
2828
- Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810
29+
- Fix issue where capitalised type variables were only allowed in certain positions. https://github.com/rescript-lang/rescript-compiler/pull/6820
2930

3031
# 11.1.1
3132

jscomp/syntax/src/res_core.ml

+7-3
Original file line numberDiff line numberDiff line change
@@ -4024,7 +4024,9 @@ and parseTypeVarList p =
40244024
match p.Parser.token with
40254025
| SingleQuote ->
40264026
Parser.next p;
4027-
let lident, loc = parseLident p in
4027+
let lident, loc =
4028+
parseIdent ~msg:ErrorMessages.typeParam ~startPos:p.startPos p
4029+
in
40284030
let var = Location.mkloc lident loc in
40294031
loop p (var :: vars)
40304032
| _ -> List.rev vars
@@ -4194,7 +4196,9 @@ and parseTypeAlias p typ =
41944196
| As ->
41954197
Parser.next p;
41964198
Parser.expect SingleQuote p;
4197-
let ident, _loc = parseLident p in
4199+
let ident, _loc =
4200+
parseIdent ~msg:ErrorMessages.typeParam ~startPos:p.startPos p
4201+
in
41984202
(* TODO: how do we parse attributes here? *)
41994203
Ast_helper.Typ.alias
42004204
~loc:(mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos)
@@ -4988,7 +4992,7 @@ and parseTypeConstraint p =
49884992
Parser.next p;
49894993
Parser.expect SingleQuote p;
49904994
match p.Parser.token with
4991-
| Lident ident ->
4995+
| Lident ident | Uident ident ->
49924996
let identLoc = mkLoc startPos p.endPos in
49934997
Parser.next p;
49944998
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)