-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Typing regression in 4.14 involving objects with constrained self type #11195
Comments
cc @garrigue |
To give a bit of context: we use this pattern to implement mixins, as follows class type has_f =
object
method f: int
end
class virtual d =
object (self : 'd)
constraint 'd = #has_f
method g = self # f
end
class my_f : has_f =
object
method f = 42
end
class e =
object
inherit d
inherit my_f
end In general, |
Personally, I agree with the type-checker: your virtual methods are not declared. I'd probably write your example like this instead: class virtual has_f =
object
method virtual f: int
end
class virtual d =
object (self)
inherit has_f
method g = self # f
end
class my_f =
object
inherit has_f
method f = 42
end
class e =
object
inherit d
inherit my_f
end However, we should probably avoid the regression anyway. It shouldn't be too hard to change the definition of undeclared to allow for the method to be declared via a type constraint on self. |
Playing with the example has revealed a more serious regression. This code: class virtual has_f = object
method virtual f: int
end
class my_f : has_f = object
method f = 9
end should be an error but is currently accepted. Previously it gave: Error: This class should be virtual. The following methods are undefined : f |
In my view this is a bit inconsistent with the fact that the type-checker interprets methods introduced by constraining self as virtual methods when inferring the type of the class:
I gave this one a try: #11204 |
triggers a warning in 4.14:
while it is accepted by previous versions. EDIT: I tweaked the example for clarity.
The text was updated successfully, but these errors were encountered: