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

Closed
vicuna opened this issue Jul 5, 2016 · 1 comment
Closed

Bug in mcomp_fields leads to segfault #7284

vicuna opened this issue Jul 5, 2016 · 1 comment
Assignees

Comments

@vicuna
Copy link

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

end

module M = struct

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

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

end

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

end

module N = F(M)

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

@vicuna
Copy link
Author

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.

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

2 participants