Skip to content

Commit d24fbeb

Browse files
authored
Merge pull request rescript-lang#188 from aspeddro/fix-constraint
fix: type constraint
2 parents 7690f08 + 50d417c commit d24fbeb

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

grammar.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,22 @@ module.exports = grammar({
259259
optional('export'),
260260
'type',
261261
optional('rec'),
262-
$._type_declaration,
262+
$._type_declaration
263263
),
264264

265265
_type_declaration: $ => seq(
266266
choice($.type_identifier, $.type_identifier_path),
267267
optional($.type_parameters),
268268
optional(seq(
269-
choice('=', '+='),
270-
optional('private'),
271-
$._type,
272-
repeat($.type_constraint),
273269
optional(seq('=', $._type)),
274-
optional(alias($._type_declaration_and, $.type_declaration)),
270+
optional(seq(
271+
choice('=', '+='),
272+
optional('private'),
273+
$._type,
274+
)),
275+
repeat($.type_constraint),
275276
)),
277+
optional(alias($._type_declaration_and, $.type_declaration))
276278
),
277279

278280
_type_declaration_and: $ => seq(

test/corpus/type_declarations.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ Opaque
55
type t
66
type t'
77
type \"type"
8+
type t and b
89

910
---
1011

1112
(source_file
1213
(type_declaration (type_identifier))
1314
(type_declaration (type_identifier))
14-
(type_declaration (type_identifier)))
15+
(type_declaration (type_identifier))
16+
(type_declaration (type_identifier)
17+
(type_declaration (type_identifier))))
1518

1619
===========================================
1720
Export
@@ -539,6 +542,7 @@ Type constraint
539542

540543
type t<'a> = 'a constraint 'a = int
541544
type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
545+
type t<'a> constraint 'a = t
542546

543547
---
544548

@@ -562,4 +566,11 @@ type decorator<'a, 'b> = 'a => 'b constraint 'a = int constraint 'b = _ => _
562566
(type_identifier)
563567
(function_type
564568
(function_type_parameters (type_identifier))
565-
(type_identifier)))))
569+
(type_identifier))))
570+
571+
(type_declaration
572+
(type_identifier)
573+
(type_parameters (type_identifier))
574+
(type_constraint
575+
(type_identifier)
576+
(type_identifier))))

0 commit comments

Comments
 (0)