You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am noticing a regression in the code for the reactive UI library I'm in the process of writing (Dec), which uses a base class called "Observable", and subclasses (like "State") that inherit this base class.
Essentially, in my library, this code sample used to work:
But no longer does due to the way I use inheritance.
Code to reproduce this issue:
--!stricttypeBaseClass=typeof(setmetatable(
{},
({} :: any) :: {__add: (BaseClass, BaseClass) ->BaseClass})
)
typeSubClass=BaseClass & {extraField: string}
-- OKlocalfunctionadd1(x: BaseClass, y: BaseClass): BaseClassreturnx+yend-- OKlocalfunctionadd2(x: SubClass, y: BaseClass): BaseClassreturnx+yend-- OKlocalfunctionadd3(x: BaseClass, y: SubClass): BaseClassreturnx+yend-- Emits an Error: "Type Error: (22,9) Type 't1 & {| extraField: string |} where-- t1 = { @metatable {| __add: (t1, t1) -> t1 |}, { } }' could not be converted-- into 'number'; none of the intersection parts are compatiblelocalfunctionadd4(x: SubClass, y: SubClass): BaseClassreturnx+yend
The first three examples correctly emit no warnings, as SubClass structurally relates to BaseClass in the overload for the __add metamethod. However, if there is not at least one operands which is exactly equal to BaseClass, even if both operands are structurally relatable to the BaseClass, an error is emitted.
The expected behavior is for all four functions to not emit any static analysis errors.
The text was updated successfully, but these errors were encountered:
AmberGraceSoftware
changed the title
Regression involving Math Overloads & Duck Typing
Regression involving Math Overloads & Intersection Types
Aug 7, 2023
I simplified the repro example in the original issue. Hopefully this can help in developing tests for fixing this regression and making sure it doesn't happen again.
Looking at the git blame for the code I edited, it seems like this may have not actually been a recent regression, but rather I failed to notice this being an issue originally? Hard to say.
I am noticing a regression in the code for the reactive UI library I'm in the process of writing (Dec), which uses a base class called "Observable", and subclasses (like "State") that inherit this base class.
Essentially, in my library, this code sample used to work:
But no longer does due to the way I use inheritance.
Code to reproduce this issue:
The first three examples correctly emit no warnings, as SubClass structurally relates to BaseClass in the overload for the
__add
metamethod. However, if there is not at least one operands which is exactly equal to BaseClass, even if both operands are structurally relatable to the BaseClass, an error is emitted.The expected behavior is for all four functions to not emit any static analysis errors.
The text was updated successfully, but these errors were encountered: