Skip to content

Commit

Permalink
parser.mly: mark punned label as ghost in object clone expr and give …
Browse files Browse the repository at this point in the history
…correct loc
  • Loading branch information
nojb committed Aug 5, 2021
1 parent e0cb3ab commit 34c662c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ let exp_of_longident ~loc lid =
ghexp ~loc (Pexp_ident lid)

let exp_of_label ~loc lbl =
mkexp ~loc (Pexp_ident (loc_lident lbl))
ghexp ~loc (Pexp_ident (loc_lident lbl))

let pat_of_label lbl =
Pat.mk ~loc:lbl.loc (Ppat_var (loc_last lbl))
Expand Down Expand Up @@ -2653,7 +2653,7 @@ record_expr_content:
match oe with
| None ->
(* No expression; this is a pun. Desugar it. *)
exp_of_label ~loc:$sloc label
exp_of_label ~loc:$loc(label) label
| Some e ->
e
in
Expand Down
45 changes: 45 additions & 0 deletions testsuite/tests/parsetree/locations_test.compilers.reference
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,51 @@ Ptop_def
]

val x : int ref -> int = <fun>
Ptop_def
[
structure_item (//toplevel//[2,1+0]..[3,9+50])
Pstr_value Nonrec
[
<def>
pattern (//toplevel//[2,1+4]..[2,1+5])
Ppat_any
expression (//toplevel//[3,9+2]..[3,9+50])
Pexp_object
class_structure
pattern (//toplevel//[3,9+8]..[3,9+8]) ghost
Ppat_any
[
class_field (//toplevel//[3,9+9]..[3,9+21])
Pcf_val Immutable
"foo" (//toplevel//[3,9+13]..[3,9+16])
Concrete Fresh
expression (//toplevel//[3,9+19]..[3,9+21])
Pexp_constant PConst_int (12,None)
class_field (//toplevel//[3,9+22]..[3,9+46])
Pcf_method Public
"x" (//toplevel//[3,9+29]..[3,9+30])
Concrete Fresh
expression (//toplevel//[3,9+31]..[3,9+46]) ghost
Pexp_poly
expression (//toplevel//[3,9+31]..[3,9+46]) ghost
Pexp_fun
Nolabel
None
pattern (//toplevel//[3,9+31]..[3,9+34])
Ppat_var "foo" (//toplevel//[3,9+31]..[3,9+34])
expression (//toplevel//[3,9+37]..[3,9+46])
Pexp_override
[
<override> "foo" (//toplevel//[3,9+40]..[3,9+43])
expression (//toplevel//[3,9+40]..[3,9+43]) ghost
Pexp_ident "foo" (//toplevel//[3,9+40]..[3,9+43])
]
None
]
]
]

- : < x : int -> 'a > as 'a = <obj>
Ptop_def
[
structure_item (//toplevel//[4,19+0]..[4,19+26])
Expand Down
4 changes: 4 additions & 0 deletions testsuite/tests/parsetree/locations_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ let x = function { contents : int } -> contents;;

let x = function { contents : int = i } -> i;;

let _ =
object val foo = 12 method x foo = {< foo >} end
;;

(* Local open *)

let x = M.{ contents = 3 };;
Expand Down

0 comments on commit 34c662c

Please sign in to comment.