Skip to content

Commit a62067d

Browse files
committed
Example of complex pattern for untagged variant.
From #6108
1 parent 77334f7 commit a62067d

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

jscomp/test/UntaggedVariants.js

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UntaggedVariants.res

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,33 @@ module OptionUnboxingHeuristic = {
293293
type untaggedInlineMultinaryOption = A | B({x: option<int>, y?: string})
294294
let untaggedInlineMultinaryOption = (x: untaggedInlineMultinaryOption) => Some(x)
295295
}
296+
297+
module ComplexPattern = {
298+
@unboxed
299+
type rec t =
300+
| @as(undefined) Missing
301+
| @as(false) False
302+
| @as(true) True
303+
| @as(null) Null
304+
| String(string)
305+
| Number(float)
306+
| Object(Js.Dict.t<t>)
307+
| Array(array<t>)
308+
309+
type tagged_t =
310+
| JSONFalse
311+
| JSONTrue
312+
| JSONNull
313+
| JSONString(string)
314+
| JSONNumber(float)
315+
| JSONObject(Js.Dict.t<t>)
316+
| JSONArray(array<t>)
317+
318+
let someJson: t = %raw(`'[{"name": "Haan"}, {"name": "Mr"}, false]'`)->Obj.magic
319+
320+
let check = s =>
321+
switch s {
322+
| Array([True, False, Array([String("My name is"), Number(10.)])]) => Js.log("yup")
323+
| _ => Js.log("Nope...")
324+
}
325+
}

0 commit comments

Comments
 (0)