Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

We've found a bug for you!
/.../fixtures/gadt_match_without_locally_abstract_type.res:6:5

4 ┆ switch x {
5 ┆ | I => 1
6 ┆ | S => "s"
7 ┆ }
8 ┆

This pattern matches values of type t<string>
but a pattern was expected which matches values of type t<int>

The incompatible parts:
string vs int
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

We've found a bug for you!
/.../fixtures/polymorphic_recursion_without_annotation.res:6:26

4 ┆ switch n {
5 ┆ | Flat(_) => 0
6 ┆ | Nest(n) => 1 + depth(n)
7 ┆ }
8 ┆

This has type: nested<array<'a>>
But this function argument is expecting: nested<'a>
The type variable 'a occurs inside array<'a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type rec t<_> = I: t<int> | S: t<string>

let f = x =>
switch x {
| I => 1
| S => "s"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type rec nested<'a> = Flat('a) | Nest(nested<array<'a>>)

let rec depth = n =>
switch n {
| Flat(_) => 0
| Nest(n) => 1 + depth(n)
}
318 changes: 318 additions & 0 deletions tests/tests/src/advanced_types_test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,318 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mocha from "mocha";
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.mjs";
import * as Test_utils from "./test_utils.mjs";
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs";
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs";

function useIdentity(param) {
let id = param.id;
return [
id(1),
id("s")
];
}

let arrayMapper = {
map: (xs, f) => xs.map(f)
};

function singleton(x) {
return [x];
}

let withDefault_1 = [2];

let withDefault = [
1,
withDefault_1
];

function sum(l) {
if (typeof l !== "object") {
return 0;
}
let match = l.VAL;
return match[0] + sum(match[1]) | 0;
}

function keep(x) {
return x;
}

function describeColor(c) {
if (c === "Blue") {
return "blue";
} else {
return "basic " + c;
}
}

function make(n) {
if (n > 0) {
return n;
}
}

let Positive = {
make: make
};

function parse(s) {
let n = Stdlib_Int.fromString(s);
if (n !== undefined) {
return {
TAG: "Number",
_0: n
};
} else {
return {
TAG: "Word",
_0: s
};
}
}

let Token = {
parse: parse
};

function make$1(x) {
return Primitive_option.some(x);
}

function get(x) {
return Stdlib_Option.getOrThrow(x, undefined);
}

let Box = {
make: make$1,
get: get
};

let widened = "A";

function make$2(x) {
return [x];
}

function toArray(t) {
return t;
}

let IntContainer = {
make: make$2,
toArray: toArray
};

function compare(a, b) {
return a - b | 0;
}

let IntOrd = {
compare: compare
};

function max(a, b) {
if ((a - b | 0) > 0) {
return a;
} else {
return b;
}
}

let IntMax = {
O: IntOrd,
max: max
};

function Apply(F) {
return X => F(X);
}

function Reverse(X) {
let compare = (a, b) => X.compare(b, a);
return {
compare: compare
};
}

function compare$1(a, b) {
return b - a | 0;
}

let ReverseInt = {
compare: compare$1
};

function Counter($star) {
let count = {
contents: 0
};
let next = () => {
count.contents = count.contents + 1 | 0;
return count.contents;
};
return {
count: count,
next: next
};
}

let count = {
contents: 0
};

function next() {
count.contents = count.contents + 1 | 0;
return count.contents;
}

let Counter1 = {
count: count,
next: next
};

let count$1 = {
contents: 0
};

function next$1() {
count$1.contents = count$1.contents + 1 | 0;
return count$1.contents;
}

let Counter2 = {
count: count$1,
next: next$1
};

function showValue(m) {
return m.show(m.value);
}

function valueOf(m) {
return m.value;
}

function show(n) {
return n.toString();
}

let IntValue = {
value: 3,
show: show
};

Mocha.describe("Advanced_types_test", () => {
Mocha.test("polymorphic fields", () => {
Test_utils.eq("File \"advanced_types_test.res\", line 144, characters 7-14", [
1,
"s"
], useIdentity({
id: x => x
}));
Test_utils.eq("File \"advanced_types_test.res\", line 146, characters 6-13", [
[2],
["a!"]
], [
arrayMapper.map([1], x => x + 1 | 0),
arrayMapper.map(["a"], s => s + "!")
]);
Test_utils.eq("File \"advanced_types_test.res\", line 150, characters 7-14", [
[1],
["a"]
], [
[1],
["a"]
]);
});
Mocha.test("constraint and alias", () => {
Test_utils.eq("File \"advanced_types_test.res\", line 154, characters 7-14", [
1,
[2]
], withDefault);
Test_utils.eq("File \"advanced_types_test.res\", line 155, characters 7-14", 3, sum({
NAME: "Cons",
VAL: [
1,
{
NAME: "Cons",
VAL: [
2,
"Nil"
]
}
]
}));
Test_utils.eq("File \"advanced_types_test.res\", line 156, characters 7-14", "B", "B");
});
Mocha.test("type pattern", () => {
Test_utils.eq("File \"advanced_types_test.res\", line 160, characters 7-14", "basic Red", "basic Red");
Test_utils.eq("File \"advanced_types_test.res\", line 161, characters 7-14", "blue", "blue");
});
Mocha.test("private types", () => {
Test_utils.eq("File \"advanced_types_test.res\", line 166, characters 20-27", 4, 3 + 1 | 0);
Test_utils.eq("File \"advanced_types_test.res\", line 169, characters 7-14", undefined, undefined);
let n = parse("7");
let tmp;
tmp = n.TAG === "Word" ? 0 : n._0;
Test_utils.eq("File \"advanced_types_test.res\", line 171, characters 6-13", 7, tmp);
});
Mocha.test("variance", () => Test_utils.eq("File \"advanced_types_test.res\", line 181, characters 7-14", "A", Stdlib_Option.getOrThrow(widened, undefined)));
Mocha.test("signatures", () => {
Test_utils.eq("File \"advanced_types_test.res\", line 185, characters 7-14", [1], [1]);
Test_utils.eq("File \"advanced_types_test.res\", line 186, characters 7-14", 9, 9);
Test_utils.eq("File \"advanced_types_test.res\", line 187, characters 7-14", 2, 2);
});
Mocha.test("functors", () => {
Test_utils.ok("File \"advanced_types_test.res\", line 191, characters 7-14", compare$1(1, 2) > 0);
Test_utils.eq("File \"advanced_types_test.res\", line 192, characters 7-14", 1, next());
Test_utils.eq("File \"advanced_types_test.res\", line 193, characters 7-14", 2, next());
Test_utils.eq("File \"advanced_types_test.res\", line 194, characters 7-14", 1, next$1());
});
Mocha.test("first-class modules", () => {
Test_utils.eq("File \"advanced_types_test.res\", line 198, characters 7-14", "3", (3).toString());
Test_utils.eq("File \"advanced_types_test.res\", line 199, characters 7-14", 3, 3);
});
});

let IntOrdCopy = IntOrd;

let Positive$make = make;

let Box$make = make$1;

let IntContainer$make = make$2;

export {
useIdentity,
arrayMapper,
singleton,
withDefault,
sum,
keep,
describeColor,
Positive,
Token,
Box,
widened,
IntContainer,
IntOrd,
IntMax,
IntOrdCopy,
Apply,
Reverse,
ReverseInt,
Counter,
Counter1,
Counter2,
showValue,
valueOf,
IntValue,
Positive$make,
Box$make,
IntContainer$make,
}
/* Not a pure module */
Loading
Loading