Skip to content

Commit df1bc3d

Browse files
authored
Variant type spreads (#6316)
* parse ... in variants * initial implementation of expanding variant type spreads * transfer attributes * comments and clarifications * ensure that variant spreads are compliant with the underlying variants runtime configuration, and get some basic error reporting going * proper error reporting for non-discoverable types * report errors on duplicate constructors in spreads * error on type parameters in variant type spreads * make inline records work when spreading variants
1 parent 9040d1e commit df1bc3d

24 files changed

+540
-23
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_duplicate_constructors.res:3:22
4+
5+
1 │ type a = One | Two
6+
2 │ type b = Two | Three
7+
3 │ type c = | ...a | ...b | Four
8+
4 │
9+
10+
Variant b has a constructor named Two, but a constructor named Two already exists in the variant it's spread into.
11+
You cannot spread variants with overlapping constructors.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_inline_records.res:4:16-30
4+
5+
2 │ type b = | ...a | Three
6+
3 │
7+
4 │ let b: b = One({name: "hello"})
8+
9+
Some required record fields are missing:
10+
age. If this is a component, add the missing props.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_recursive.res:1:65
4+
5+
1 │ type rec a = One | Two | Three and b = Four | Five and c = | ...a | ...b
6+
2 │
7+
8+
This type could not be found. It's only possible to spread variants that are known as the spread happens. This means for example that you can't spread variants in recursive definitions.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_tag_missing.res:2:15
4+
5+
1 │ @tag("kind") type a = One(int) | Two(string)
6+
2 │ type b = | ...a | Three(bool)
7+
3 │
8+
9+
The @tag attribute does not match for this variant and the variant where this is spread. Both variants must have the same @tag attribute configuration, or no @tag attribute at all.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_tag_value_mismatch.res:2:28
4+
5+
1 │ @tag("kind") type a = One(int) | Two(string)
6+
2 │ @tag("name") type b = | ...a | Three(bool)
7+
3 │
8+
9+
The @tag attribute does not match for this variant and the variant where this is spread. Both variants must have the same @tag attribute configuration, or no @tag attribute at all.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_type_parameters.res:2:15
4+
5+
1 │ type a<'a> = One | Two('a)
6+
2 │ type b = | ...a<int> | Three
7+
8+
Type parameters are not supported in variant type spreads.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_spread_unboxed_mismatch.res:2:15
4+
5+
1 │ @unboxed type a = One(int) | Two(string)
6+
2 │ type b = | ...a | Three(bool)
7+
3 │
8+
9+
This variant is unboxed, but the variant where this is spread is not. Both variants unboxed configuration must match.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type a = One | Two
2+
type b = Two | Three
3+
type c = | ...a | ...b | Four
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type a = One({name: string, age: int}) | Two
2+
type b = | ...a | Three
3+
4+
let b: b = One({name: "hello"})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type rec a = One | Two | Three and b = Four | Five and c = | ...a | ...b

0 commit comments

Comments
 (0)