Skip to content

Commit b6ac0aa

Browse files
committed
Reason v4 - Parse Hashtags for polymorphic variants.
Summary: Implements parsing for "hashtags" polymorphic variant constructors. Since Reason Syntax still supports object syntax, we needed to rearrange some syntactic real estate to make this work. ```reason let red = #FF000; let isRed = color => switch(color) { | #FF0000 => true | _ => false }; let callAMethod = someObject::methodName(isRed, "testing red"); let templateLiteral = ` String template literals are still using backticks. String template literals are still using backticks. `; ``` Test Plan: Reviewers: CC:
1 parent ce9fac6 commit b6ac0aa

20 files changed

+681
-265
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Even if you have an explicit v3.6 marker.
3+
* This whole file wil be auto-upaded to 3.8 becase something uses
4+
* angle brackets.
5+
*/;
6+
[@reason.version 3.8];
7+
let watchThisIsOldStyle: list<int> = [1, 2];
8+
9+
let watchThisIsOldStylePoly = #hello;
10+
11+
/**
12+
* This will cause the whole file to be promoted.
13+
*/
14+
let x: list<int> = [1, 3];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[@reason.version 3.8];
2+
/**
3+
* Test auto-promotion based on feature inference even if no version
4+
* tag. By default you're using the old 3.7.
5+
*/
6+
let watchThisIsOldStyle: list<int> = [1, 2];
7+
8+
let watchThisIsOldStylePoly = #hello;
9+
10+
/**
11+
* This will cause the whole file to be promoted.
12+
*/
13+
let x: list<int> = [1, 3];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[@reason.version 3.7];
2+
/**
3+
* This should just print a 3.7 version attr at the top.
4+
*/
5+
let watchThisIsOldStyle: list(int) = [1, 2];

formatTest/typeCheckedTests/expected_output/oo_3_dot_8.re

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@
22

33
[@reason.version 3.8];
44

5+
type canStillDefineConst =
6+
| []
7+
| ::(int, canStillDefineConst);
8+
59
class virtual stack <'a> (init) = {
10+
as self;
611
/*
712
* The "as this" is implicit and will be formatted away.
813
*/
914
val virtual dummy: unit;
1015
val mutable v: list<'a> = init;
1116
pub virtual implementMe: int => int;
17+
pub is_empty = () =>
18+
switch (v) {
19+
| [] => true
20+
| _ => false
21+
};
22+
pub is_empty_unitless =
23+
switch (v) {
24+
| [] => true
25+
| _ => false
26+
};
27+
pub empty_unitless = {
28+
v = [];
29+
self;
30+
};
31+
pub empty = () => {
32+
v = [];
33+
self;
34+
};
1235
pub pop =
1336
switch (v) {
1437
| [hd, ...tl] =>
@@ -90,6 +113,15 @@ class extendedStackAcknowledgeOverride
90113

91114
let inst = (new extendedStack)([1, 2]);
92115

116+
let wasItFull =
117+
!inst::empty()::empty_unitless::is_empty();
118+
// this is the same
119+
let wasItFull' =
120+
!inst::empty()::empty_unitless::is_empty();
121+
122+
let orig_not = (!);
123+
let (!) = o => o::empty();
124+
93125
/**
94126
* Recursive classes.
95127
*/
@@ -195,7 +227,7 @@ let acceptsOpenAnonObjAsArg =
195227
y: int,
196228
},
197229
) =>
198-
o#x + o#y;
230+
o::x + o::y;
199231
let acceptsClosedAnonObjAsArg =
200232
(
201233
o: {
@@ -204,7 +236,7 @@ let acceptsClosedAnonObjAsArg =
204236
y: int,
205237
},
206238
) =>
207-
o#x + o#y;
239+
o::x + o::y;
208240
let res =
209241
acceptsOpenAnonObjAsArg({
210242
pub x = 0;
@@ -346,13 +378,13 @@ let x: tupleClass<int, int> = {
346378
pub pr = (10, 10)
347379
};
348380

349-
let x: #tupleClass<int, int> = x;
381+
let x: *tupleClass<int, int> = x;
350382

351383
let incrementMyClassInstance:
352-
(int, #tupleClass<int, int>) =>
353-
#tupleClass<int, int> =
384+
(int, *tupleClass<int, int>) =>
385+
*tupleClass<int, int> =
354386
(i, inst) => {
355-
let (x, y) = inst#pr;
387+
let (x, y) = inst::pr;
356388
{pub pr = (x + i, y + i)};
357389
};
358390

@@ -361,7 +393,7 @@ class myClassWithNoTypeParams = {};
361393
* The #myClassWithNoTypeParams should be treated as "simple"
362394
*/
363395
type optionalMyClassSubtype<'a> =
364-
option<#myClassWithNoTypeParams> as 'a;
396+
option<*myClassWithNoTypeParams> as 'a;
365397

366398
/**
367399
* Remember, "class type" is really "class_instance_type" (which is the type of
@@ -398,7 +430,7 @@ class addablePoint:
398430
one: addablePointClassType,
399431
two: addablePointClassType,
400432
) =>
401-
one#x + two#x + one#y + two#x;
433+
one::x + two::x + one::y + two::x;
402434
pub x: int = init;
403435
pub y = init;
404436
};
@@ -412,7 +444,7 @@ class addablePoint2:
412444
one: addablePointClassType,
413445
two: addablePointClassType,
414446
) =>
415-
one#x + two#x + one#y + two#x;
447+
one::x + two::x + one::y + two::x;
416448
pub x: int = init;
417449
pub y = init;
418450
};

formatTest/typeCheckedTests/expected_output/typeParameters.re

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/**
22
* Testing type parameters.
33
*/;
4-
[@reason.version 3.7];
4+
[@reason.version 3.8];
55

6-
type threeThings('t) = ('t, 't, 't);
7-
type listOf('t) = list('t);
6+
type threeThings<'t> = ('t, 't, 't);
7+
type listOf<'t> = list<'t>;
88

9-
type underscoreParam(_) =
9+
type underscoreParam<_> =
1010
| Underscored;
11-
type underscoreParamCovariance(+_) =
11+
type underscoreParamCovariance<+_> =
1212
| Underscored;
13-
type underscoreParamContravariance(-_) =
13+
type underscoreParamContravariance<-_> =
1414
| Underscored;
1515

16-
type tickParamCovariance(+'a) =
16+
type tickParamCovariance<+'a> =
1717
| Underscored;
18-
type tickParamContravariance(-'a) =
18+
type tickParamContravariance<-'a> =
1919
| Underscored;
2020

21-
let x: option(list('a)) = None;
22-
type myFunctionType('a) = (
23-
list(('a, 'a)),
24-
int => option(list('a)),
21+
let x: option<list<'a>> = None;
22+
type myFunctionType<'a> = (
23+
list<('a, 'a)>,
24+
int => option<list<'a>>,
2525
);
26-
let funcAnnoted = (~a: list(int)=[0, 1], ()) => a;
26+
let funcAnnoted = (~a: list<int>=[0, 1], ()) => a;
2727

2828
/**
2929
* Syntax that would be likely to conflict with lexing parsing of < > syntax.
@@ -46,12 +46,12 @@ let isSuperGreaterThanEqNegFive3 = zero >>= (-5);
4646

4747
let jsx = (~children, ()) => 0;
4848

49-
type t('a) = 'a;
50-
let optionArg = (~arg: option(t(int))=?, ()) => arg;
49+
type t<'a> = 'a;
50+
let optionArg = (~arg: option<t<int>>=?, ()) => arg;
5151
let optionArgList =
52-
(~arg: option(list(list(int)))=?, ()) => arg;
53-
let defaultJsxArg = (~arg: t(int)=<jsx />, ()) => arg;
54-
let defaultFalse = (~arg: t(bool)=!true, ()) => arg;
52+
(~arg: option<list<list<int>>>=?, ()) => arg;
53+
let defaultJsxArg = (~arg: t<int>=<jsx />, ()) => arg;
54+
let defaultFalse = (~arg: t<bool>=!true, ()) => arg;
5555
/* Doesn't work on master either let defaultTrue = (~arg:t<bool>= !!true) => arg; */
5656

5757
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Even if you have an explicit v3.6 marker.
3+
* This whole file wil be auto-upaded to 3.8 becase something uses
4+
* angle brackets.
5+
*/
6+
[@reason.version 3.6];
7+
let watchThisIsOldStyle : list(int) = [1, 2];
8+
9+
let watchThisIsOldStylePoly = `hello;
10+
11+
/**
12+
* This will cause the whole file to be promoted.
13+
*/
14+
let x : list<int> = [1, 3];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Test auto-promotion based on feature inference even if no version
3+
* tag. By default you're using the old 3.7.
4+
*/
5+
let watchThisIsOldStyle : list(int) = [1, 2];
6+
7+
let watchThisIsOldStylePoly = `hello;
8+
9+
/**
10+
* This will cause the whole file to be promoted.
11+
*/
12+
let x : list<int> = [1, 3];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* This should just print a 3.7 version attr at the top.
3+
*/
4+
let watchThisIsOldStyle : list(int) = [1, 2];
5+

formatTest/typeCheckedTests/input/oo_3_dot_8.re

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,36 @@
22

33
[@reason.version 3.8];
44

5+
type canStillDefineConst =
6+
| []
7+
| :: (int, canStillDefineConst);
8+
59
class virtual stack('a) (init) = {
10+
as self;
611
/*
712
* The "as this" is implicit and will be formatted away.
813
*/
914
val virtual dummy: unit;
1015
val mutable v: list<'a> = init;
1116
pub virtual implementMe: int => int;
17+
pub is_empty = () =>
18+
switch (v) {
19+
| [] => true
20+
| _ => false
21+
};
22+
pub is_empty_unitless =
23+
switch (v) {
24+
| [] => true
25+
| _ => false
26+
};
27+
pub empty_unitless = {
28+
v = [];
29+
self
30+
};
31+
pub empty = () => {
32+
v = [];
33+
self;
34+
};
1235
pub pop =
1336
switch (v) {
1437
| [hd, ...tl] =>
@@ -90,6 +113,15 @@ class extendedStackAcknowledgeOverride
90113

91114
let inst = (new extendedStack)([1, 2]);
92115

116+
let wasItFull = !inst::empty()::empty_unitless::is_empty();
117+
// this is the same
118+
let wasItFull' = !(inst::empty()::empty_unitless::is_empty());
119+
120+
let orig_not = (!);
121+
let (!) = o => o::empty();
122+
123+
124+
93125
/**
94126
* Recursive classes.
95127
*/
@@ -195,7 +227,7 @@ let acceptsOpenAnonObjAsArg =
195227
y: int,
196228
},
197229
) =>
198-
o#x + o#y;
230+
o::x + o::y;
199231
let acceptsClosedAnonObjAsArg =
200232
(
201233
o: {
@@ -204,7 +236,7 @@ let acceptsClosedAnonObjAsArg =
204236
y: int,
205237
},
206238
) =>
207-
o#x + o#y;
239+
o::x + o::y;
208240
let res =
209241
acceptsOpenAnonObjAsArg({
210242
pub x = 0;
@@ -346,13 +378,13 @@ let x: tupleClass<int, int> = {
346378
pub pr = (10, 10)
347379
};
348380

349-
let x: #tupleClass<int, int> = x;
381+
let x: *tupleClass<int, int> = x;
350382

351383
let incrementMyClassInstance:
352-
(int, #tupleClass<int, int>) =>
353-
#tupleClass<int, int> =
384+
(int, *tupleClass<int, int>) =>
385+
*tupleClass<int, int> =
354386
(i, inst) => {
355-
let (x, y) = inst#pr;
387+
let (x, y) = inst::pr;
356388
{pub pr = (x + i, y + i)};
357389
};
358390

@@ -361,7 +393,7 @@ class myClassWithNoTypeParams = {};
361393
* The #myClassWithNoTypeParams should be treated as "simple"
362394
*/
363395
type optionalMyClassSubtype<'a> =
364-
option< #myClassWithNoTypeParams> as 'a;
396+
option< *myClassWithNoTypeParams> as 'a;
365397

366398
/**
367399
* Remember, "class type" is really "class_instance_type" (which is the type of
@@ -398,7 +430,7 @@ class addablePoint:
398430
one: addablePointClassType,
399431
two: addablePointClassType,
400432
) =>
401-
one#x + two#x + one#y + two#x;
433+
one::x + two::x + one::y + two::x;
402434
pub x: int = init;
403435
pub y = init;
404436
};
@@ -412,7 +444,7 @@ class addablePoint2:
412444
one: addablePointClassType,
413445
two: addablePointClassType,
414446
) =>
415-
one#x + two#x + one#y + two#x;
447+
one::x + two::x + one::y + two::x;
416448
pub x: int = init;
417449
pub y = init;
418450
};

formatTest/unit_tests/expected_output/class_types.re

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ class type t = {
3737
class type t = {
3838
open M;
3939
};
40+
41+
class intTuplesTuples =
42+
class tupleClass(
43+
#tupleClass(int, int),
44+
#tupleClass(int, int),
45+
);
46+
47+
class intTuplesTuples =
48+
class tupleClass(
49+
#tupleClass(int, int),
50+
#tupleClass(int, int),
51+
);

0 commit comments

Comments
 (0)