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

Bug in mcomp_fields leads to segfault #7284

vicuna opened this issue Jul 5, 2016 · 1 comment

Bug in mcomp_fields leads to segfault #7284

vicuna opened this issue Jul 5, 2016 · 1 comment


Copy link

@vicuna vicuna commented Jul 5, 2016

Original bug ID: 7284
Reporter: @lpw25
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-09-24T15:33:05Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 4.03.0
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: typing
Monitored by: @alainfrisch

Bug description

I think that this condition in mcomp_fields:

if miss1 <> [] && (object_row ty1).desc = Tnil
|| miss2 <> [] && (object_row ty2).desc = Tnil then raise (Unify []);

is supposed to be:

if miss1 <> [] && (object_row ty2).desc = Tnil
|| miss2 <> [] && (object_row ty1).desc = Tnil then raise (Unify []);

As it stands the check treats some compatible types as incompatible. For example, the following code gives a segmentation fault:

module type S = sig

type o1 = < bar : int; foo : int >
type o2 = private < foo : int; .. >

type v1 = T of o1
type v2 = T of o2


module M = struct

type o1 = < bar : int; foo : int >
type o2 = o1

type v1 = T of o1
type v2 = v1 = T of o2


module F(X : S) = struct

type 'a wit =
| V1 : string -> X.v1 wit
| V2 : int -> X.v2 wit

let f : X.v1 wit -> unit = function V1 s -> print_endline s


module N = F(M)

let () = N.f (N.V2 0)

Copy link

@vicuna vicuna commented Jul 6, 2016

Comment author: @garrigue

Fixed in trunk by commit cae15ea.

The code for the object case was completely broken.
Actually, the correct condition is even a bit more complex, but this was overlooked.
The variant case was checked more carefully.

@vicuna vicuna closed this Sep 24, 2017
@vicuna vicuna added the typing label Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.