Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005839OCaml-for Camlp4 use 22:452015-12-11 19:08
Assigned Togasche 
StatusclosedResolutionnot fixable 
PlatformOSOS Version
Product Version4.00.0 
Target VersionFixed in Version 
Summary0005839: Camlp4 incorrectly expands a quotation containing an 'assert false' expression.
DescriptionSummary: 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 Reproducerun 'make strange' to see the compilation error.

then run 'make expected' to see the generated file (called and see that it is interpreted by the toplevel without any problem.
TagsNo tags attached.
Attached Filesgz file icon table_bug.tar.gz [^] (699 bytes) 2012-12-02 22:45

- Relationships

-  Notes
pveber (reporter)
2012-12-02 22:57

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.
gasche (developer)
2012-12-02 23:29

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.)
hongboz (developer)
2012-12-03 06:13

we may give a warning for this case
pveber (reporter)
2012-12-03 09:46

Thanks Gabriel for the explanation, I wasn't aware of this peculiarity. Sorry for wasting your time!
frisch (developer)
2012-12-03 18:44

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.

- Issue History
Date Modified Username Field Change
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 [^]
2016-02-08 12:50 doligez Category for Camlp4 use [^] => for Camlp4 use [^]
2017-02-23 16:43 doligez Category for Camlp4 use [^] => -for Camlp4 use [^]

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker