You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7285 Reporter:@lpw25 Assigned to:@garrigue Status: closed (set by @xavierleroy on 2017-09-24T15:33:06Z) Resolution: fixed Priority: normal Severity: minor Version: 4.03.0 Fixed in version: 4.04.0 +dev / +beta1 / +beta2 Category: typing Tags: testsuite, typing Monitored by:@bobzhang@gasche@hcarty
Bug description
In principal mode generalize_structure is used for contravariant variables. However, generalize_structure ignores variables which have already been generalized. This means that instead of generalizing variables which occur only in covariant positions, we generalize any variable which is first encountered in a covariant position.
For example, the following code is allowed and results in a segmentation fault:
OCaml version 4.03.0
#principal true;;
module M : sig
type (+'a, -'b) foo
val apply : ('a, 'b) foo -> 'b -> 'a
val f : unit -> ('a, 'a) foo
end = struct
type ('a, 'b) foo = 'b -> 'a
let apply f x = f x
let f () =
let r = ref None in
fun x ->
match !r with
| None -> r := Some x; x
| Some y -> r := Some x; y
end;;
module M :
sig
type (+'a, -'b) foo
val apply : ('a, 'b) foo -> 'b -> 'a
val f : unit -> ('a, 'a) foo
end
let f = M.f ();;
val f : ('a, 'a) M.foo =
M.apply f 0;;
: int = 0
print_endline (M.apply f "World");;
Process ocaml-toplevel segmentation fault (core dumped)
Reversing the order of the type arguments of M.foo gives a type error as expected, since the variable is encountered in a contravariant position first.
The text was updated successfully, but these errors were encountered:
A rather bad bug indeed. (Unlike some other tricky type-system bugs,) I think we could have caught this one with a slightly more proactive testing strategy, testing as much generalization behaviors as possible. Marking the issue as testsuite-related in case people are interested in working on this.
Part of the reason it went undetected is that -principal was not used much until recently.
And I admit that the change to generalize_contravariant was stupid (it should have come with a few tests...)
Original bug ID: 7285
Reporter: @lpw25
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-09-24T15:33:06Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.03.0
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: typing
Tags: testsuite, typing
Monitored by: @bobzhang @gasche @hcarty
Bug description
In principal mode
generalize_structure
is used for contravariant variables. However,generalize_structure
ignores variables which have already been generalized. This means that instead of generalizing variables which occur only in covariant positions, we generalize any variable which is first encountered in a covariant position.For example, the following code is allowed and results in a segmentation fault:
#principal true;;
module M : sig
module M :
sig
type (+'a, -'b) foo
val apply : ('a, 'b) foo -> 'b -> 'a
val f : unit -> ('a, 'a) foo
end
let f = M.f ();;
val f : ('a, 'a) M.foo =
M.apply f 0;;
print_endline (M.apply f "World");;
Process ocaml-toplevel segmentation fault (core dumped)
Reversing the order of the type arguments of
M.foo
gives a type error as expected, since the variable is encountered in a contravariant position first.The text was updated successfully, but these errors were encountered: