Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

camlp4 creates wrong location for type definitions #5374

Closed
vicuna opened this issue Oct 12, 2011 · 2 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Oct 12, 2011

Original bug ID: 5374
Reporter: furuse
Assigned to: @xclerc
Status: closed (set by @xavierleroy on 2012-09-25T18:07:21Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.12.1
Fixed in version: 3.12.1+dev
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: @hcarty

Bug description

Camlp4 creates an AST with a wrong location information of the following simple type definition:

----------- p4bug.ml
type t

ocamlc -pp camlp4o -c p4bug.ml

The type declaration is at line 2, characters 0--1 , which is just after the real location, where nothing exists. It should be line 1, characters 0-5 or something around it.

(This issue is one of the causes of wrong location information in CamlSpotter.)

@vicuna

This comment has been minimized.

Copy link
Author

commented Oct 12, 2011

Comment author: furuse

The following patch seems to fix the issue, but not sure. Please review:

diff -r 2aa557dc10ec -r 6c3e3f09464f camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml
--- a/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml Sat Oct 08 15:55:45 2011 +0900
+++ b/camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml Wed Oct 12 15:52:35 2011 +0900
@@ -346,7 +346,7 @@
mktype loc tl cl Ptype_abstract (mkprivate' pflag) m ]
;

  • value type_decl tl cl t = type_decl tl cl (loc_of_ctyp t) None False t;
  • value type_decl tl cl t loc = type_decl tl cl loc None False t;

    value mkvalue_desc t p = {pval_type = ctyp t; pval_prim = p};

@@ -835,7 +835,7 @@
match x with
[ <:ctyp< $x$ and $y$ >> ->
mktype_decl x (mktype_decl y acc)

  • | Ast.TyDcl _ c tl td cl ->
  • | Ast.TyDcl _loc c tl td cl ->
    let cl =
    List.map
    (fun (t1, t2) ->
    @@ -843,7 +843,7 @@
    (ctyp t1, ctyp t2, mkloc loc))
    cl
    in
  •    [(c, type_decl (List.fold_right type_parameters tl []) cl td) :: acc]
    
  •    [(c, type_decl (List.fold_right type_parameters tl []) cl td _loc) :: acc]
    
    | _ -> assert False ]
    and module_type =
    fun
    diff -r 2aa557dc10ec -r 6c3e3f09464f camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml
    --- a/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml Sat Oct 08 15:55:45 2011 +0900
    +++ b/camlp4/Camlp4Parsers/Camlp4OCamlRevisedParser.ml Wed Oct 12 15:52:35 2011 +0900
    @@ -1004,7 +1004,7 @@
    ;
    opt_eq_ctyp:
    [ [ "="; tk = type_kind -> tk
  •    | -> <:ctyp<>> ] ]
    
  •    | -> let _loc = Loc.ghost in <:ctyp<>> ] ]
    
    ;
    type_kind:
    [ [ t = ctyp -> t ] ]
@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 20, 2011

Comment author: @diml

Patch reviewed and applied. Thanks.

Commits 11901 and 11903.

@vicuna vicuna closed this Sep 25, 2012

@vicuna vicuna added camlp4 bug labels Mar 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.