Skip to content

Mutable field update ignored in closure #7789

@vicuna

Description

@vicuna

Original bug ID: 7789
Reporter: tbrk
Assigned to: @gasche
Status: resolved (set by @gasche on 2018-05-02T20:17:55Z)
Resolution: not a bug
Priority: high
Severity: major
Platform: x86_64
OS: MacOS / Debian Linux
OS Version: 10.11.6 / 9.4
Version: 4.06.1
Fixed in version: 4.06.0
Category: misc
Monitored by: @nojb @yallop

Bug description

Consider the following program:

type data = { mutable n  : int; }

let f { n } t = Printf.printf "n=%d\n%!" n

let go udata g =
  g 1.0;
  udata.n <- 10;
  g 1.0
;;

let udata = { n = 0 } in
go udata (f udata);;

In OCaml <= 4.05.0, it prints (correctly):
n=0
n=10

In OCaml 4.06.0 and 4.07.0+beta2 (at least), it prints (incorrectly):
n=0
n=0

Steps to reproduce

Compile the above program with ocamlc or ocamlopt, or enter it into the top-level.

Additional information

The given code is a reduced form from a larger example:
https://github.com/inria-parkas/sundialsml/blob/55a05d3794e98e1d4b3f9953088e41ef6f359bb2/examples/arkode/C_serial/ark_heat1D_adapt.ml#L155

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions