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
Missed Type-error leads to a segfault upon record access #6505
Comments
Comment author: @damiendoligez I followed your steps to reproduce, but "make" doesn't seem to build "simTest.native" or any other executable. |
Comment author: @yallop Here's a simpler example: $ cat bang.ml class c = let c' = (new c)#set_y (Some (M.abs (object end))) $ ocaml bang.ml |
Comment author: choeger @dolligez: Sorry, you have to run |
Comment author: @garrigue In yallop's example, yhe problem here is apparent in the signature inferred for M: module M : The type ('a is_an_object as 'a) does not make sense. |
Comment author: @garrigue Fixed in branch 4.02, at revision 15038. Thank you Jeremy for providing a compact reproduction case. Error: The definition of abs contains a cycle: Actually, I'm rather surprised you could trigger this bug just by sheer chance, because it is a conjunction of a lot of things. |
Comment author: choeger Does that mean, you cannot define a constraint now, where you use the a type variable on the rhs of object methods? I am relying on the ability to express class type constraints, where methods deliver a new object of the class that fulfills the constraint. i.e. an iterator would have the type: type 'a iterator = <next : 'a option ; ..> as 'a |
Comment author: @garrigue No, the algorithm just checked that you are not creating "black holes", I.e. cycles that do not contain any type constructor. A cycle going through an object type is fine. |
Comment author: @garrigue Looking at the output of the test case, the behavior with or without -principal is different, so I reopen this report. (Not dangerous, but disturbing) |
Comment author: @stedolan The problem still seems to be there. The recursion in 'abs' is inessential, and here's a slight variant without it: $ ocaml -version class c = let c' = (new c)#set_y (Some (M.abs (object end))) |
Comment author: @stedolan Hmm, this seems to be a regression. My version does not segfault in 4.02.1, while in 4.03 even this shorter program crashes: type 'o is_an_object = < .. > as 'o Very oddly, in 4.02.1 this program does not crash when run with "ocaml bang.ml", but does crash when copy-pasted into the toplevel. |
Comment author: @lpw25 Same issue for polymorphic variants: type 'v is_a_variant = [> ] as 'v |
Comment author: @garrigue Fixed in trunk by commit 848c20f. In order to properly fix this in the -principal case to, had to make the handling of recursive types more restrictive in mutually recursive definitions. Error messages are not so good, but I see no easy way to avoid it. |
Original bug ID: 6505
Reporter: choeger
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-09-24T15:33:04Z)
Resolution: fixed
Priority: low
Severity: crash
Version: 4.01.0
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: typing
Related to: #5343
Parent of: #6496
Monitored by: @yallop
Bug description
This is a rather large and complex codebase, so forgive me that this bug report is not (yet) in a usable form. I hope for the active help from OCaml devs here to nail down the exact source and a minimal triggering example.
Anyway. In the code found here:
https://github.com/AMSUN-Berlin/ocsimrun/tree/typecheck_bug
I encountered something that seems to be a type-error that went unnoticed by OCaml 4.01
In sim.ml I put a record (sim_state) in my extensible state monad (e.g. here: https://github.com/AMSUN-Berlin/ocsimrun/blob/typecheck_bug/simulation/sim.ml#L193 ), and in my test-case, I get an option value (e.g. here: https://github.com/AMSUN-Berlin/ocsimrun/blob/typecheck_bug/tests/simTests.ml#L50 ). Obviously, I made a simple mistake in sim.ml, but the typechecker won't take notice of it.
In the consequence, this test program crashes with a segmentation fault.
Steps to reproduce
The branch is already somewhat stripped down. To compile it, you will need the dependencies (all installable via opam):
opam install pa_monad_custom, batteries, pa_comprehension, ounit
Then you can checkout the demonstration code:
git clone https://github.com/AMSUN-Berlin/ocsimrun.git
git checkout typecheck_bug
To build:
oasis setup && ./configure && make
And run the test:
./simTests.native
Additional information
As mentioned, I am aware that the code is quite large. Any help/hints to strip it down further is appreciated. Unfortunately, I don't have the time to dig it out all alone, but I felt such a bug is too important to be left unnoticed.
File attachments
The text was updated successfully, but these errors were encountered: