Skip to content

Commit 60cf75a

Browse files
authored
Exploring variant-to-variant coercion (#6314)
* sketch out variant-to-variant coercion * reuse logic from ast_untagged_variants * reuse more logic * handle inline records in variant coercion * fix false positive in variant to primitive branch, and add tests * changelog * format * reuse more logic from ast_untagged * remove unused
1 parent 48e4372 commit 60cf75a

18 files changed

+237
-86
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
> - :nail_care: [Polish]
1212
1313
# 11.0.0-beta.4 (Unreleased)
14+
#### :rocket: New Feature
15+
- Variants: Allow coercing from variant to variant, where applicable. https://github.com/rescript-lang/rescript-compiler/pull/6314
1416

1517
# 11.0.0-beta.3
1618

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_to_variant_coercion.res:6:10-15
4+
5+
4 │ let x: x = One(true)
6+
5 │
7+
6 │ let y = (x :> y)
8+
7 │
9+
10+
Type x is not a subtype of y
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_to_variant_coercion_as.res:6:10-15
4+
5+
4 │ let x: x = One(true)
6+
5 │
7+
6 │ let y = (x :> y)
8+
7 │
9+
10+
Type x is not a subtype of y
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_to_variant_coercion_tag.res:6:10-15
4+
5+
4 │ let x: x = One(true)
6+
5 │
7+
6 │ let y = (x :> y)
8+
7 │
9+
10+
Type x is not a subtype of y
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_to_variant_coercion_unboxed.res:6:10-15
4+
5+
4 │ let x: x = One(true)
6+
5 │
7+
6 │ let y = (x :> y)
8+
7 │
9+
10+
Type x is not a subtype of y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type x = One(bool) | Two
2+
type y = One(string) | Two
3+
4+
let x: x = One(true)
5+
6+
let y = (x :> y)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type x = | @as("one") One(bool) | Two(string)
2+
type y = One(bool) | Two(string)
3+
4+
let x: x = One(true)
5+
6+
let y = (x :> y)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@tag("kind") type x = One(bool) | Two(string)
2+
type y = One(bool) | Two(string)
3+
4+
let x: x = One(true)
5+
6+
let y = (x :> y)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@unboxed type x = One(bool) | Two
2+
type y = One(bool) | Two
3+
4+
let x: x = One(true)
5+
6+
let y = (x :> y)

jscomp/core/matching_polyfill.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
let () = Ast_untagged_variants.extract_concrete_typedecl := Ctype.extract_concrete_typedecl
26+
2527
let names_from_construct_pattern (pat : Typedtree.pattern) =
2628
let rec resolve_path n (path : Path.t) =
2729
match Env.find_type path pat.pat_env with

0 commit comments

Comments
 (0)