-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Return types of intersection of functions are incomplete and depend on order of declaration - an algorithm to fix it #57089
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
Comments
You are contradicting yourself. In your motivating examples you use unions for the return types, in your "proposed algorithm" you use an intersection for the return types. |
@MartinJohns - I am well aware of that (notice that the issue is closed). Consider this intersection:
Then an Talking about the In #57087, the user is always required to define a (usually overloaded) function type to pass as the argument to be checked by the parameter intersection type. The whole argument is checked against the In contrast, here in #57089 we are querying locations of a manually defined (think factory farmed) intersection type and getting back an arbitrary, narrow type value that satisfies that type. What users seems to need here is to get, at each query point, the union of all intersection-valid argument types at that query point. Another issue (not this one) is that using a manually defined intersection to define a type - often used as a quick way to define a composite type - is not a good way to define a composite type. It would be better to define a composition tool(s) to create composite types from other types. Type composition need not be equal to type intersection, the latter of which has a specific meaning in CFA. |
Itβs not (you appear to have reopened it prior to Martinβs reply). |
My bad. Re-opened as #57095. |
π Search Terms
intersection of functions, return type, incomplete, declaration order dependent
#57002
β Viability Checklist
β Suggestion
The return type of an intersection of functions should be complete and independent of the order of declaration of the functions.
An algorithm is proposed to achieve that.
π Motivating Example
The proposed algorithm is
g = g[0], g[1], ...
be intersection of functions.args
be the arguments.returnType = never
// initializeg[i]
ing
args
extendsParameters<g[i]>
thenreturnType = returnType & ReturnType<g[i]>
returnType
The current algorithm is just to route the call to
chooseOverload
and treatbar
exactly as though it were an ordered overload function. Thereforebar
can match at most one of its intersection members, resulting in an incomplete and declaration order dependent return type.π» Use Cases
Would resolve issue #57002.
There is no easy workaround now.
The text was updated successfully, but these errors were encountered: