|
| 1 | +(* TEST |
| 2 | + * expect |
| 3 | +*) |
| 4 | + |
| 5 | +let pos_a : lexing_position = {Lexing.dummy_pos with pos_fname = "a"};; |
| 6 | +let pos_b : lexing_position = {Lexing.dummy_pos with pos_fname = "b"};; |
| 7 | +[%%expect{| |
| 8 | +val pos_a : lexing_position = |
| 9 | + {pos_fname = "a"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1} |
| 10 | +val pos_b : lexing_position = |
| 11 | + {pos_fname = "b"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1} |
| 12 | +|}] |
| 13 | + |
| 14 | +let f = fun ~(a:[%src_pos]) ~(b:[%src_pos]) () -> a, b |
| 15 | +[%%expect{| |
| 16 | +val f : |
| 17 | + a:[%src_pos] -> b:[%src_pos] -> unit -> lexing_position * lexing_position = |
| 18 | + <fun> |
| 19 | +|}] |
| 20 | + |
| 21 | +let _ = f ~b:pos_b ~a:pos_a () ;; |
| 22 | +[%%expect{| |
| 23 | +- : lexing_position * lexing_position = |
| 24 | +({pos_fname = "a"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}, |
| 25 | + {pos_fname = "b"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}) |
| 26 | +|}] |
| 27 | + |
| 28 | +(* Partial application *) |
| 29 | +let x = f ~b:pos_b ;; |
| 30 | +let y = x ~a:pos_a ;; |
| 31 | +let z = y () ;; |
| 32 | +[%%expect {| |
| 33 | +val x : a:[%src_pos] -> unit -> lexing_position * lexing_position = <fun> |
| 34 | +val y : unit -> lexing_position * lexing_position = <fun> |
| 35 | +val z : lexing_position * lexing_position = |
| 36 | + ({pos_fname = "a"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}, |
| 37 | + {pos_fname = "b"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}) |
| 38 | +|}] |
| 39 | + |
| 40 | +let g = fun ~(a:[%src_pos]) ?(c = 0) ~(b:[%src_pos]) () -> a, b, c |
| 41 | +[%%expect{| |
| 42 | +val g : |
| 43 | + a:[%src_pos] -> |
| 44 | + ?c:int -> b:[%src_pos] -> unit -> lexing_position * lexing_position * int = |
| 45 | + <fun> |
| 46 | +|}] |
| 47 | + |
| 48 | +let _ = g ~b:pos_b ~a:pos_a () ;; |
| 49 | +[%%expect{| |
| 50 | +- : lexing_position * lexing_position * int = |
| 51 | +({pos_fname = "a"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}, |
| 52 | + {pos_fname = "b"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}, 0) |
| 53 | +|}] |
| 54 | + |
| 55 | +let h = fun ~(a:[%src_pos]) ~(b:int) () -> a, b |
| 56 | +[%%expect{| |
| 57 | +val h : a:[%src_pos] -> b:int -> unit -> lexing_position * int = <fun> |
| 58 | +|}] |
| 59 | + |
| 60 | +let _ = h ~b:0 ~a:pos_a ();; |
| 61 | +[%%expect{| |
| 62 | +- : lexing_position * int = |
| 63 | +({pos_fname = "a"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1}, 0) |
| 64 | +|}] |
| 65 | + |
| 66 | +let k = fun ~(a:int) ~(a:[%src_pos])() -> a |
| 67 | +[%%expect{| |
| 68 | +val k : a:int -> a:[%src_pos] -> unit -> lexing_position = <fun> |
| 69 | +|}] |
| 70 | + |
| 71 | +let _ = k ~a:Lexing.dummy_pos ~a:0 ();; |
| 72 | +[%%expect{| |
| 73 | +Line 1, characters 13-29: |
| 74 | +1 | let _ = k ~a:Lexing.dummy_pos ~a:0 ();; |
| 75 | + ^^^^^^^^^^^^^^^^ |
| 76 | +Error: This expression has type Lexing.position = lexing_position |
| 77 | + but an expression was expected of type int |
| 78 | +|}] |
| 79 | + |
| 80 | +let _ = k ~a:0 ~a:Lexing.dummy_pos ();; |
| 81 | +[%%expect{| |
| 82 | +- : Lexing.position = |
| 83 | +{Lexing.pos_fname = ""; pos_lnum = 0; pos_bol = 0; pos_cnum = -1} |
| 84 | +|}] |
| 85 | + |
| 86 | +(* Labels on source positions can't commute in definitions *) |
| 87 | +let m : a:[%src_pos] -> b:[%src_pos] -> unit -> unit = fun ~(b:[%src_pos]) ~(a:[%src_pos]) () -> () |
| 88 | +[%%expect{| |
| 89 | +Line 1, characters 55-99: |
| 90 | +1 | let m : a:[%src_pos] -> b:[%src_pos] -> unit -> unit = fun ~(b:[%src_pos]) ~(a:[%src_pos]) () -> () |
| 91 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 92 | +Error: This function should have type |
| 93 | + a:[%src_pos] -> b:[%src_pos] -> unit -> unit |
| 94 | + but its first argument is ~(b:[%src_pos]) instead of ~(a:[%src_pos]) |
| 95 | +|}] |
0 commit comments