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 accepts bad syntax and may also bomb on it #5705

Closed
vicuna opened this issue Jul 29, 2012 · 3 comments
Closed

Camlp4 accepts bad syntax and may also bomb on it #5705

vicuna opened this issue Jul 29, 2012 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Jul 29, 2012

Original bug ID: 5705
Reporter: @mmottl
Status: closed (set by @damiendoligez on 2015-01-13T18:20:26Z)
Resolution: suspended
Priority: normal
Severity: minor
Version: 4.00.0
Target version: undecided
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: @mmottl

Bug description

The following file "x.ml" will lead to a syntax error with "ocaml x.ml":

let f x : type a. a = ()

But "camlp4o x.ml" will accept and print the human-readable format.

By contrast, "ocamldep -pp camlp4o x.ml" will bomb:

Assertion failed, file "camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml", line 284, char 8
Preprocessing error on file x.ml
x.cmo :
x.cmx :
EXIT STATUS 2

@vicuna
Copy link
Author

vicuna commented Jul 31, 2012

Comment author: @bobzhang

It's weird (-verbose) will change the semantics of camlp4 parser
camlp4>camlp4o -filter lift -str 'let f x : type a . a = () '
let loc = Loc.ghost
in
Ast.StVal (loc, Ast.ReNil,
(Ast.BiEq (loc, (Ast.PaId (loc, (Ast.IdLid (loc, "f")))),
(Ast.ExFun (loc,
(Ast.McArr (loc, (Ast.PaId (loc, (Ast.IdLid (loc, "x")))),
(Ast.ExNil loc),
(Ast.ExTyc (loc, (Ast.ExId (loc, (Ast.IdUid (loc, "()")))),
(Ast.TyTypePol (loc,
(Ast.TyId (loc, (Ast.IdLid (loc, "a")))),
(Ast.TyId (loc, (Ast.IdLid (loc, "a")))))))))))))))

camlp4>camlp4o -verbose -filter lift -str 'let f x : type a . a = () '


Parse error in entry [ctyp], rule:
[ TRY [ a_LIDENT; ":" ]; ctyp LEVEL "star"; "->"; SELF ]

let loc = Loc.ghost
in
Ast.StVal (loc, Ast.ReNil,
(Ast.BiEq (loc, (Ast.PaId (loc, (Ast.IdLid (loc, "f")))),
(Ast.ExFun (loc,
(Ast.McArr (loc, (Ast.PaId (loc, (Ast.IdLid (loc, "x")))),
(Ast.ExNil loc),
(Ast.ExTyc (loc, (Ast.ExId (loc, (Ast.IdUid (loc, "()")))),
(Ast.TyTypePol (loc,
(Ast.TyId (loc, (Ast.IdLid (loc, "a")))),
(Ast.TyId (loc, (Ast.IdLid (loc, "a")))))))))))))))

@vicuna
Copy link
Author

vicuna commented Sep 23, 2012

Comment author: @bobzhang

the problem comes from the entry cvalue_binding
cvalue_binding:
| ":"; "type"; t1 = unquoted_typevars; "." ; t2 = ctyp ; "="; e = expr ->
let u = Ast.TyTypePol _loc t1 t2 in
<:expr< ($e : $u) >>
The parser goes from binding -> fun_binding -> cvalue_binding.
Would it be safe to delete this rule?
cvalue_binding is invoked in another place
| o = value_val_opt_override; mf = opt_mutable; lab = label; e = cvalue_binding ->
<:class_str_item< value $override:o $mutable:mf $lab = $e >>

@vicuna
Copy link
Author

vicuna commented Jan 13, 2015

Comment author: @damiendoligez

Transferred to camlp4/camlp4#75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant