-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
How to reproduce:
Run the ppx in automatic mode on :
module M = struct
type t = A | B
end
class a =
object
method f = M.A
end
class b =
object
inherit a
method! f = B
endWhat happens ?
Class b get translated into:
class b =
object
inherit a
method! f =
Landmark.enter __generated_landmark;
let r = try B with e -> (Landmark.exit __generated_landmark; Landmark.raise e) in
Landmark.exit __generated_landmark;
r
endwhich triggers "Error: Unbound constructor B" because the typechecker does not know at this point that the B has the same type as the method's returned type.
Proposed Solution
We could add type annotations ("'a") to guide the inference (we have to make sure that 'a is fresh of course).
class b =
object
inherit a
method! f : 'a =
Landmark.enter __generated_landmark;
let r = try (B : 'a) with e -> (Landmark.exit __generated_landmark; Landmark.raise e) in
Landmark.exit __generated_landmark;
r
endIf there's an annotation on the returned type we probably should copy it around the body in a similar fashion.
Metadata
Metadata
Assignees
Labels
No labels