|Anonymous | Login | Signup for a new account||2016-10-27 14:56 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0005839||OCaml||for Camlp4 use https://github.com/ocaml/camlp4/issues||public||2012-12-02 22:45||2015-12-11 19:08|
|Target Version||Fixed in Version|
|Summary||0005839: Camlp4 incorrectly expands a quotation containing an 'assert false' expression.|
|Description||Summary: attached to this bug report is a tiny syntax extension which leads to a typing error in "compilation mode" on a simple example. However, when using camlp4 to generate an .ml file in the same setting, the generated program is correct.|
In more details: the syntax extension expands a record-like type declaration to a module type in a signature and to a module in a structure. There is only one function in the generated module. While its signature is correct in the module type, the generated implementation is wrongly typed and produces a 'signature mismatch' error when compiled.
However, when I generate the ml file with camlp4 first, the generated file is correct and there is no problem when compiled.
|Steps To Reproduce||run 'make strange' to see the compilation error. |
then run 'make expected' to see the generated file (called expected.ml) and see that it is interpreted by the toplevel without any problem.
|Tags||No tags attached.|
|Attached Files||table_bug.tar.gz [^] (699 bytes) 2012-12-02 22:45|
Just one remark,
changing line 15
value input () = assert $`bool:false$;
value input () = failwith "";
value input () = failwith $`str:""$;
solves the problem. So the issue seems related to the use of assert.
This is not a Camlp4 bug but an oddity in the semantics of "assert false".
OCaml recognizes two *different* syntactic constructors:
- assert false (that generates the parstree Pexp_assertfalse)
- assert foo (for foo <> false) (Pexp_assert (...))
The first has type 'a, the second has type unit. You can check this with:
# fun x -> assert x;;
- : bool -> unit = <fun>
Now your code actually produces the second construction, rather than the first, because of the antiquotation indirection (which prevents the parser from recognizing the special case). The expression has type unit and therefore the module doesn't type-check.
Now if you print the Camlp4 output to a file, you get "assert false" which is re-parsed into the special-case construct.
This is not a problem with Camlp4 itself, but rather with assert.
(The option -dparsetree is fairly useful in debugging those problems: you get to see a dump of the OCaml parsetree after the camlp4 preprocessing step. I was reminded of the difference by comparing the output of -dparsetree for the two ways to compile your file.)
|we may give a warning for this case|
|Thanks Gabriel for the explanation, I wasn't aware of this peculiarity. Sorry for wasting your time!|
A typical example where writing correct Camlp4 code requires expert knowledge about OCaml's AST, even though Camlp4 tries hard to hide this AST from you.
Well, in this case, I would have expected Camlp4 to try to fix this weird behavior of OCaml syntax, by having a single node for "assert", mapping to the correct one according to whether the argument turns out to be "False" or not. This would introduce some "discontinuity", but this might be less surprising for the user.
|2012-12-02 22:45||pveber||New Issue|
|2012-12-02 22:45||pveber||File Added: table_bug.tar.gz|
|2012-12-02 22:57||pveber||Note Added: 0008551|
|2012-12-02 23:29||gasche||Note Added: 0008552|
|2012-12-02 23:29||gasche||Status||new => resolved|
|2012-12-02 23:29||gasche||Resolution||open => not fixable|
|2012-12-02 23:29||gasche||Assigned To||=> gasche|
|2012-12-03 06:13||hongboz||Note Added: 0008553|
|2012-12-03 09:46||pveber||Note Added: 0008554|
|2012-12-03 18:44||frisch||Note Added: 0008557|
|2015-12-11 19:08||xleroy||Status||resolved => closed|
|2016-02-08 12:49||doligez||Category||Camlp4 => for Camlp4 use https://github.com/ocaml/camlp4/issues/102 [^]|
|2016-02-08 12:50||doligez||Category||for Camlp4 use https://github.com/ocaml/camlp4/issues/102 [^] => for Camlp4 use https://github.com/ocaml/camlp4/issues [^]|
|Copyright © 2000 - 2011 MantisBT Group|