Skip to content

Commit

Permalink
Merge pull request #10764 from alainfrisch/afrisch_fix_oo_compil
Browse files Browse the repository at this point in the history
Fix miscompilation of method delegation
  • Loading branch information
Octachron committed Nov 19, 2021
2 parents 91995de + 47657f4 commit 5928536
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ OCaml 4.14.0
- #10735: Uncaught unify exception from `build_as_type`
(Jacques Garrigue, report and review by Leo White)

- #10763, #10764: fix miscompilation of method delegation
(Alain Frisch, review by Vincent Laviron and Jacques Garrigue)


OCaml 4.13 maintenance branch
Expand Down
9 changes: 1 addition & 8 deletions lambda/translclass.ml
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,13 @@ let transl_class_rebind ~scopes cl vf =

(* Rewrite a closure using builtins. Improves native code size. *)

let rec module_path = function
Lvar id ->
let s = Ident.name id in s <> "" && s.[0] >= 'A' && s.[0] <= 'Z'
| Lprim(Pfield _, [p], _) -> module_path p
| Lprim(Pgetglobal _, [], _) -> true
| _ -> false

let const_path local = function
Lvar id -> not (List.mem id local)
| Lconst _ -> true
| Lfunction {kind = Curried; body} ->
let fv = free_variables body in
List.for_all (fun x -> not (Ident.Set.mem x fv)) local
| p -> module_path p
| _ -> false

let rec builtin_meths self env env2 body =
let const_path = const_path (env::self) in
Expand Down
14 changes: 14 additions & 0 deletions testsuite/tests/basic/objects.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(* TEST *)


(* Non-regression for bug #10763, fixed in #10764 *)

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
1 change: 1 addition & 0 deletions testsuite/tests/basic/objects.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK 3

0 comments on commit 5928536

Please sign in to comment.