-
Notifications
You must be signed in to change notification settings - Fork 111
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
Type error when referring to subinterface in where but not a primitive #837
Comments
To get the behavior you expect, where a method is declared in a parent type, and then have it redeclared in the child type with local interface Base is Instance
where self.class.name == "Base"
Test1: function(self)
end From https://github.com/teal-language/tl/blob/master/docs/tutorial.md#interfaces :
|
Found a subsequent issue (might move to another issue) Granted, I might modify middleclass to make instance functions a subtable (or ditch it entirely and do manual classes), but middleclass and penlight (most common class libraries) by default have instance functions defined on the class local interface Class
name: string
end
local interface Instance
class: Class
end
local interface testFuns
Test2: function(self)
end
local interface Base is Instance, testFuns
where self.class.name == "Base"
Test1: function(self)
end
local interface testFuns2 is testFuns
Test2: function(self, a?: number)
end
local interface Extended is Base, testFuns2
where self.class.name == "Extended"
end
local extended = {} as Extended
function extended.Test1(self: Extended) -- Fine
end
function extended.Test2(self: Extended, a?:number) -- type signature of 'Test2' does not match its declaration in Extended: different number of input arguments: method and non-method are not the same type
end |
The above example works if you replace local interface testFuns2 is testFuns with local interface testFuns2 and perform the inheritance only in local interface Extended is testFuns2, Base |
I was going to comment on the fact that removing the inheritence would allow the types to become incompatible, but I found removing the optional from a actually marked an error, however not sure if this is a good thing as the interface becomes magically inherited outside its definition (implicit side effect) |
I am not entirely sure what's going on here (title will likely need updating) but minimal test case:
The text was updated successfully, but these errors were encountered: