Skip to content

Commit c8ed227

Browse files
authored
Coerce polyvariant to variant (#6981)
* wip coerce polyvariant to variant * fix unboxed catch-all * logic * cleanup * add fixture tests for polyvariant to variant coercion * changelog
1 parent 094fb15 commit c8ed227

15 files changed

+187
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 12.0.0-alpha.2 (Unreleased)
1414

15+
#### :rocket: New Feature
16+
17+
- Allow coercing polyvariants to variants when we can guarantee that the runtime representation matches. https://github.com/rescript-lang/rescript-compiler/pull/6981
18+
1519
#### :nail_care: Polish
1620

1721
- Improve formatting in the generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6932
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_coercion_open_polyvariant.res:5:19-30
4+
5+
3 │ let p = #One
6+
4 │
7+
5 │ let v: variant = (p :> variant)
8+
6 │
9+
10+
Type [> #One] is not a subtype of variant
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_coercion_polyvariant_mismatch_as_attribute.res:7:19-30
4+
5+
5 │ let p: poly = #One
6+
6 │
7+
7 │ let v: variant = (p :> variant)
8+
8 │
9+
10+
Type poly = [#One | #Two] is not a subtype of variant
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/variant_coercion_polyvariant_mismatch_as_attribute2.res:7:19-30
4+
5+
5 │ let p: poly = #One
6+
6 │
7+
7 │ let v: variant = (p :> variant)
8+
8 │
9+
10+
Type poly = [#One | #Two] is not a subtype of variant
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_coercion_polyvariant_unmatched_cases.res:7:19-30
4+
5+
5 │ let p: poly = #One
6+
6 │
7+
7 │ let v: variant = (p :> variant)
8+
8 │
9+
10+
Type poly = [#One | #Two] is not a subtype of variant
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_coercion_polyvariant_with_payload.res:7:19-30
4+
5+
5 │ let p: poly = #One
6+
6 │
7+
7 │ let v: variant = (p :> variant)
8+
8 │
9+
10+
Type poly = [#One | #Two(string)] is not a subtype of variant
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type variant = One | Two
2+
3+
let p = #One
4+
5+
let v: variant = (p :> variant)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type poly = [#One | #Two]
2+
3+
type variant = One | @as("two") Two
4+
5+
let p: poly = #One
6+
7+
let v: variant = (p :> variant)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type poly = [#One | #Two]
2+
3+
type variant = One | @as(2) Two
4+
5+
let p: poly = #One
6+
7+
let v: variant = (p :> variant)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type poly = [#One | #Two]
2+
3+
type variant = One
4+
5+
let p: poly = #One
6+
7+
let v: variant = (p :> variant)

0 commit comments

Comments
 (0)