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

Private row variables can escape their scope #7348

Closed
vicuna opened this issue Sep 9, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Sep 9, 2016

Original bug ID: 7348
Reporter: @lpw25
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2017-06-12T14:31:33Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0
Target version: 4.06.0 +dev/beta1/beta2/rc1
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: typing
Monitored by: @gasche @yallop @hcarty

Bug description

The following functor:

module F (X : sig type t = private < foo:int; ..> val x : t end) = struct
let x : < foo: int; ..> = X.x
end

has a return type that includes the private row variable from X:

module F :
functor (X : sig type t = private < foo : int; .. > val x : t end) ->
sig val x : < foo : int; .. > end

This variable remains abstract even when the functor is applied:

module M = struct
type t = < foo: int; bar: int>
let x = object
method foo = 0
method bar = 0
end
end

module N = F(M)

which has type:

module N : sig val x : < foo : int; .. > end

To see that the variable is still abstract:

module L : sig val x : < foo : int; bar : int> end = N;;

Characters 53-54:
module L : sig val x : < foo : int; bar : int> end = N;;
^
Error: Signature mismatch:
Modules do not match:
sig val x : < foo : int; .. > end
is not included in
sig val x : < bar : int; foo : int > end
Values do not match:
val x : < foo : int; .. >
is not included in
val x : < bar : int; foo : int >

let x : < foo : int; bar : int> = N.x;;

Characters 34-37:
let x : < foo : int; bar : int> = N.x;;
^^^
Error: This expression has type < foo : int; .. >
but an expression was expected of type < bar : int; foo : int >
The first object type has no method bar

I suspect that the type is called something like X.t#row and is being substituted to M.t#row which does not exist. This could possibly be
a soundness bug since different functors would produce the same
M.t#row even though they would be different types.

@vicuna

This comment has been minimized.

Copy link
Author

commented Sep 10, 2016

Comment author: @garrigue

The bug was introduced between 3.12 and 4.04, probably with the introduction of GADTs.
I will look into that.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 12, 2017

Comment author: @garrigue

Indeed the code for abstract rows assumes that they are never visible outside of their scope.
This should be true, as an abstract row can only belong to one type, but the above code reveals an expanded form.
I hope to be able to solve this through the name abbreviation mechanism, but leave it alone for now.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 12, 2017

Comment author: @garrigue

Note: printing the internal types show that the path of the (inexistent) row is correctly propagated, so at least there does not seem to be a soundness problem.

@vicuna

This comment has been minimized.

Copy link
Author

commented Jun 12, 2017

Comment author: @garrigue

Fixed in 4.05 and trunk by commits 42fb9ff and 02c4df6.

Exploit the fact that inside a module the same type name cannot be used twice, so that the type definition corresponding to a row name is unambiguous.
Ctype.normalize_type fixes printing, Subst,type_expr fixes functor application (both needed).

@vicuna vicuna closed this Jun 12, 2017

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added this to the 4.06.0 milestone 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
You can’t perform that action at this time.