-
Notifications
You must be signed in to change notification settings - Fork 802
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
Return types in shadowing members are not considered in generic constraint resolution to avoid ambiguity. #8794
Comments
What was interesting to me wasn't so much that return types aren't considered (this is the default for both C# and F#) but that overload resolution takes shadowed members into account here. |
@NinoFloris I kinda disagree: type Daddy() =
member this.Hello() =
Unchecked.defaultof<int32>
type SomeoneHolder<'Someone when 'Someone: (member Hello : unit -> string)> =
{ Someone: 'Someone }
let someoneHolder =
{ Someone = Daddy() }
Maybe we're not on the same page. The return type needs to respect the signature given in the generic constraint. So... why not the same behavior for a shadowing member? Also, I don't think it's that surprising that shadowing members are actually processed by the generic constraint resolution process. => All in all there is an issue of consistency. |
It does surprise me that the shadowed member is being taken into accdount. Since this involves SRTP constraint resolution I will investigate as part of #6805. |
We (@kerry-perret and I) discussed this briefly over the weekend and found that the code as written is documented as not being allowed. Mainly, member constraints can only be used with SRTP, and cannot be used on types (i.e., even changing Still, the error is confusing and it appears as if the compiler actually tries to resolve the member constraint here. |
Description
It seems that when a member is shadowing an inherited member with a different return type, the return type is not considered to avoid any ambiguity when the compiler is attempting to resolve the member.
Repro steps
Self-explanatory example:
Expected behavior
It should compile.
Actual behavior
It does not, with the error below:
Known workarounds
None.
Related information
Provide any related information (optional):
The return type
The text was updated successfully, but these errors were encountered: