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

Miscompilation of method delegation #10763

Closed
alainfrisch opened this issue Nov 10, 2021 · 2 comments · Fixed by #10764
Closed

Miscompilation of method delegation #10763

alainfrisch opened this issue Nov 10, 2021 · 2 comments · Fixed by #10764
Labels

Comments

@alainfrisch
Copy link
Contributor

module W = struct
  let r = ref (object method m x = Printf.printf "BAD %i\n%!" x end)
end

let proxy = object method m = (!W.r) # m end

let () =
  W.r := object method m x = Printf.printf "OK %i\n%!" x end;
  proxy # m 3

On 4.12.1 and on trunk, both with ocamlc and ocamlopt, this program prints "BAD 3" instead of "OK 3". A first look at the output of -dlambda suggests that the method m on proxy is compiled using CamlinternalOO's SendConst, reading from the W.r reference when the proxy object is created. This is not correct, because this read is impure.

@alainfrisch
Copy link
Contributor Author

alainfrisch commented Nov 10, 2021

Translclass.module_path decides that reading (Pfield) from a value accessible through a global path gives a constant, which is wrong.

@alainfrisch
Copy link
Contributor Author

AFAICT, this has been around since 2003 (f209562).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant