File tree 2 files changed +28
-21
lines changed
2 files changed +28
-21
lines changed Original file line number Diff line number Diff line change @@ -524,7 +524,25 @@ let all_record_args lbls =
524
524
(fun lbl -> (mknoloc (Longident. Lident " ?temp?" ), lbl, omega))
525
525
lbl_all
526
526
in
527
- List. iter (fun ((_ , lbl , _ ) as x ) -> t.(lbl.lbl_pos) < - x) lbls;
527
+ List. iter
528
+ (fun ((id , lbl , pat ) as x ) ->
529
+ let lbl_is_optional () =
530
+ match lbl.lbl_repres with
531
+ | Record_optional_labels labels -> List. mem lbl.lbl_name labels
532
+ | _ -> false
533
+ in
534
+ let x =
535
+ match pat.pat_desc with
536
+ | Tpat_construct
537
+ ( {txt = Longident. Ldot (Longident. Lident " *predef*" , " Some" )},
538
+ _,
539
+ [({pat_desc = Tpat_constant _} as c)] )
540
+ when lbl_is_optional () ->
541
+ (id, lbl, c)
542
+ | _ -> x
543
+ in
544
+ t.(lbl.lbl_pos) < - x)
545
+ lbls;
528
546
Array. to_list t
529
547
| _ -> fatal_error " Parmatch.all_record_args"
530
548
Original file line number Diff line number Diff line change @@ -17,33 +17,22 @@ let intDict = {
17
17
} ;
18
18
19
19
function inferDictByPattern ( dict ) {
20
- let match = dict . one ;
21
- if ( match === 1 ) {
22
- let match$1 = dict . three ;
23
- if ( match$1 === 3 ) {
24
- let match$2 = dict . four ;
25
- if ( match$2 === 4 ) {
26
- dict [ "five" ] = 5 ;
27
- return ;
28
- }
29
-
30
- }
31
-
20
+ if ( dict . one === 1 && dict . three === 3 && dict . four === 4 ) {
21
+ dict [ "five" ] = 5 ;
22
+ return ;
32
23
}
33
- let match$3 = dict . two ;
34
- if ( match$3 === 1 ) {
35
- console . log ( "two" ) ;
36
- } else {
24
+ if ( dict . two !== 1 ) {
37
25
console . log ( "not one" ) ;
26
+ } else {
27
+ console . log ( "two" ) ;
38
28
}
39
29
}
40
30
41
31
function constrainedAsDict ( dict ) {
42
- let match = dict . one ;
43
- if ( match === 1 ) {
44
- console . log ( "one" ) ;
45
- } else {
32
+ if ( dict . one !== 1 ) {
46
33
console . log ( "not one" ) ;
34
+ } else {
35
+ console . log ( "one" ) ;
47
36
}
48
37
}
49
38
You can’t perform that action at this time.
0 commit comments